GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — inspect.iscoroutinefunction / isgeneratorfunction / isasyncgenfunction can't handle partialmethod objects · Issue #82545 · python/cpython

inspect.iscoroutinefunction / isgeneratorfunction / isasyncgenfunction can't handle partialmethod objects #82545

New issue
Copy link
New issue
Copy link
Open
Open
inspect.iscoroutinefunction / isgeneratorfunction / isasyncgenfunction can't handle partialmethod objects#82545
Copy link
Labels
3.10 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

mjpieters
mannequin
opened on Oct 3, 2019
Issue body actions
BPO 38364
Nosy @mjpieters, @asvetlov, @1st1, @Dreamsorcerer, @jalaziz
PRs
  • bpo-38364: unwrap partialmethods just like we unwrap partials #16600
  • 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 = None
    created_at = <Date 2019-10-03.13:28:44.060>
    labels = ['3.8', 'type-bug', 'library', '3.9', '3.10']
    title = "inspect.iscoroutinefunction / isgeneratorfunction / isasyncgenfunction can't handle  partialmethod objects"
    updated_at = <Date 2022-03-05.22:48:08.143>
    user = 'https://github.com/mjpieters'

    bugs.python.org fields:

    activity = <Date 2022-03-05.22:48:08.143>
    actor = 'jalaziz'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2019-10-03.13:28:44.060>
    creator = 'mjpieters'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38364
    keywords = ['patch']
    message_count = 2.0
    messages = ['353849', '414598']
    nosy_count = 5.0
    nosy_names = ['mjpieters', 'asvetlov', 'yselivanov', 'dreamsorcerer', 'jalaziz']
    pr_nums = ['16600']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue38364'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    Activity

    1. mjpieters commented on Oct 3, 2019

      @mjpieters
      mjpietersmannequin
      on Oct 3, 2019
      MannequinAuthor
      More actions

      This is a follow-up to bpo-33261, which added general support for detecting generator / coroutine / async generator functions wrapped in partials. It appears that partialmethod objects were missed out.

      While a partialmethod object will produce a functools.partial() object on binding to an instance, the .func attribute of that partial is a bound method, not a function, and the current _has_code_flag implementation unwraps methods *before* it unwraps partials.

      Next, binding to a class produces a partialmethod._make_unbound_method.._method wrapper function. _unwrap_partial can't unwrap this, as it doesn't handle this case; it could look for the _partialmethod attribute and follow that to find the .func attribute.

      Test case:

      import inspect
      import functools
      
      class Foo:
          async def bar(self, a): return a
          ham = partialmethod(bar, "spam")
      
      print(inspect.iscoroutinefunction(Foo.bar)  # True
      print(inspect.iscoroutinefunction(Foo.ham)  # False
      instance = Foo()
      print(inspect.iscoroutinefunction(instance.bar)  # True
      print(inspect.iscoroutinefunction(instance.ham)  # False
      Reacted by Jan Lukány
    2. mjpieters
      added
      3.8 (EOL)end of lifeend of life
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Oct 3, 2019
    3. jalaziz commented on Mar 5, 2022

      @jalaziz
      jalazizmannequin
      on Mar 5, 2022
      Mannequin
      More actions

      I've recently ran into this via unittest.mock.patch.object. Mocking an asynchronous partial method returns MagicMock and not AsyncMagicMock, causing some pretty hard to debug failures.

    4. jalaziz
      added
      3.9 (EOL)end of lifeend of life
      3.10 (EOL)end of lifeend of life
      on Mar 5, 2022
    5. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    6. graingert commented on Jul 16, 2022

      @graingert
      graingert
      on Jul 16, 2022
      Contributor
      More actions

      see also #67707

    7. pavelm10 commented on Dec 1, 2022

      @pavelm10
      pavelm10
      on Dec 1, 2022
      More actions

      The above test case slightly changed:

      def test_dummy():
          import inspect
          import functools
      
          class Foo:
              async def bar(self, a): return a
              ham = functools.partialmethod(bar, "spam")
      
          assert inspect.iscoroutinefunction(Foo.bar)  # True
          assert not inspect.iscoroutinefunction(Foo.ham)  # False
          instance = Foo()
          assert inspect.iscoroutinefunction(instance.bar)  # True
          assert inspect.iscoroutinefunction(instance.ham)  # False

      IS NOT failing for Python 3.10.7
      IS failing for Python 3.10.2
      Other 3.10.x not tested.

    8. mjpieters commented on Dec 30, 2022

      @mjpieters
      mjpieters
      on Dec 30, 2022
      ContributorAuthor
      More actions

      The above test case slightly changed:

          assert inspect.iscoroutinefunction(Foo.bar)  # True
          assert not inspect.iscoroutinefunction(Foo.ham)  # False

      Why did you change the test to add not?

    9. serhiy-storchaka
      added this to Inspect issues 🔍on Mar 5, 2024
    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.10 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

      Projects

      • Inspect issues 🔍
        Status
        No status
        Show more project fields

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.