Skip to content

Commit

Permalink
gh-94912: Adjusted check for non-standard coroutine function marker. (#…
Browse files Browse the repository at this point in the history
…100935)

The initial implementation did not correctly identify explicitly
marked class instances.

Follow up to 532aa4e
  • Loading branch information
carltongibson authored Jan 11, 2023
1 parent 6e4e14d commit 07a87f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 0 additions & 2 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,6 @@ def _has_coroutine_mark(f):
while ismethod(f):
f = f.__func__
f = functools._unwrap_partial(f)
if not (isfunction(f) or _signature_is_functionlike(f)):
return False
return getattr(f, "_is_coroutine_marker", None) is _is_coroutine_marker

def markcoroutinefunction(func):
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ async def __call__(self):
self.assertFalse(inspect.iscoroutinefunction(Cl))
# instances with async def __call__ are NOT recognised.
self.assertFalse(inspect.iscoroutinefunction(Cl()))
# unless explicitly marked.
self.assertTrue(inspect.iscoroutinefunction(
inspect.markcoroutinefunction(Cl())
))

class Cl2:
@inspect.markcoroutinefunction
Expand All @@ -232,6 +236,10 @@ def __call__(self):
self.assertFalse(inspect.iscoroutinefunction(Cl2))
# instances with marked __call__ are NOT recognised.
self.assertFalse(inspect.iscoroutinefunction(Cl2()))
# unless explicitly marked.
self.assertTrue(inspect.iscoroutinefunction(
inspect.markcoroutinefunction(Cl2())
))

class Cl3:
@inspect.markcoroutinefunction
Expand Down

0 comments on commit 07a87f7

Please sign in to comment.