Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support functools.partial in inspect.is*function() checks #79071

Closed
asvetlov opened this issue Oct 4, 2018 · 5 comments
Closed

Support functools.partial in inspect.is*function() checks #79071

asvetlov opened this issue Oct 4, 2018 · 5 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir

Comments

@asvetlov
Copy link
Contributor

asvetlov commented Oct 4, 2018

BPO 34890
Nosy @asvetlov, @1st1, @pablogsal, @sweeneyde
PRs
  • bpo-34890: Make iscoroutinefunction, isgeneratorfunction and isasyncgenfunction work with functools.partial #9903
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-10-26.11:23:04.921>
    created_at = <Date 2018-10-04.07:29:56.296>
    labels = ['3.8', 'library']
    title = 'Support functools.partial in inspect.is*function() checks'
    updated_at = <Date 2022-02-13.06:36:40.836>
    user = 'https://github.com/asvetlov'

    bugs.python.org fields:

    activity = <Date 2022-02-13.06:36:40.836>
    actor = 'Dennis Sweeney'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-10-26.11:23:04.921>
    closer = 'pablogsal'
    components = ['Library (Lib)']
    creation = <Date 2018-10-04.07:29:56.296>
    creator = 'asvetlov'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34890
    keywords = ['patch']
    message_count = 5.0
    messages = ['327039', '327056', '327057', '328538', '413171']
    nosy_count = 4.0
    nosy_names = ['asvetlov', 'yselivanov', 'pablogsal', 'Dennis Sweeney']
    pr_nums = ['9903']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue34890'
    versions = ['Python 3.8']

    @asvetlov
    Copy link
    Contributor Author

    asvetlov commented Oct 4, 2018

    isfunction() processes both isfunction(func) and isfunction(partial(func, arg)) correctly.

    But iscoroutinefunction() misses this functionality.

    We can implement it easy by adding a check for isinstance(func, partial) and applying a coroutine check for func.func.

    Also, we can do the same for isgeneratorfunction() and isasyncgenfunction().

    The patch looks easy and straightforward.

    Yuri, what do you think about?

    @asvetlov asvetlov added 3.8 only security fixes stdlib Python modules in the Lib dir labels Oct 4, 2018
    @1st1
    Copy link
    Member

    1st1 commented Oct 4, 2018

    I think the fact that inspect.isfunction recognizes partials is a very strong argument to enable inspect.iscoroutinefunction to do so as well.

    This is a backwards incompatible change though, strictly speaking.

    @1st1
    Copy link
    Member

    1st1 commented Oct 4, 2018

    Feel free to work on the PR. If we want to push this to 3.8 we should do that now and have enough time for it to be tested.

    @pablogsal
    Copy link
    Member

    New changeset 7cd2543 by Pablo Galindo in branch 'master':
    bpo-34890: Make iscoroutinefunction, isgeneratorfunction and isasyncgenfunction work with functools.partial (GH-9903)
    7cd2543

    @sweeneyde
    Copy link
    Member

    See https://bugs.python.org/issue46722 for a concern about this change.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants