Skip to content

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

Description

@asvetlov
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']

    Activity

    1. asvetlov commented on Oct 4, 2018

      @asvetlov
      ContributorAuthor

      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?

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Oct 4, 2018
    3. 1st1 commented on Oct 4, 2018

      @1st1
      Member

      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.

    4. 1st1 commented on Oct 4, 2018

      @1st1
      Member

      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.

    5. pablogsal commented on Oct 26, 2018

      @pablogsal
      Member

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

    6. sweeneyde commented on Feb 13, 2022

      @sweeneyde
      Member

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

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.8 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions