-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
inspect.iscoroutinefunction(inspect) returns True #120200
Comments
sobolevn
added a commit
to sobolevn/cpython
that referenced
this issue
Jun 7, 2024
sobolevn
added a commit
to sobolevn/cpython
that referenced
this issue
Jun 7, 2024
sobolevn
added a commit
that referenced
this issue
Jun 7, 2024
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Jun 7, 2024
…orner case (pythonGH-120214) (cherry picked from commit 10fb1b8) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn
added a commit
to sobolevn/cpython
that referenced
this issue
Jun 7, 2024
…True` corner case (pythonGH-120214) (cherry picked from commit 10fb1b8) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn
added a commit
that referenced
this issue
Jun 7, 2024
sobolevn
added a commit
that referenced
this issue
Jun 7, 2024
Thanks everyone! |
noahbkim
pushed a commit
to hudson-trading/cpython
that referenced
this issue
Jul 11, 2024
estyxx
pushed a commit
to estyxx/cpython
that referenced
this issue
Jul 17, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
Bug description:
I would expect
inspect.iscoroutinefunction
to only return True for coroutine functions and those functions decorated withinspect.markcoroutinefunction
, but it also returns True for theinspect
module object itself.This is a regression - in 3.11 it returned False.
The issue seems to be that
iscoroutinefunction(obj)
checks ifobj._is_coroutine_marker is inspect._is_coroutine_marker
, and this check passes for obj being theinspect
module.I tested 3.12.3 but I can see that the implementation of
iscoroutinefunction
hasn't changed between 3.12.3 and the main branch (GitHub link, in particularinspect.py
line 412), so I believe the issue is still present in tip of main.The bug was triggered in our proprietary codebase in a test file that defines a number of tests as coroutine functions and then uses
checks = {k: v for k, v in globals().items() if inspect.iscoroutinefunction(v)}
to iterate over all tests. This broke when updating from 3.11 to 3.12.I think
inspect.iscoroutinefunction(inspect)
returning True is quite surprising behavior so I would propose changing inspect.py so it doesn't use the same attribute name_is_coroutine_marker
as the global variable_is_coroutine_marker
, perhaps by renaming the global to_is_coroutine_marker_object
or something.CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
inspect.iscoroutinefunction(inspect) is True
corner case #120214inspect.iscoroutinefunction(inspect) is True
corner case (GH-120214) #120237inspect.iscoroutinefunction(inspect) is True
corner case (GH-120214) #120239The text was updated successfully, but these errors were encountered: