-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-131628: use duck-typing in inspect to support Cython
#131632
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
base: main
Are you sure you want to change the base?
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the proposal, it needs tests in any case.
But, I am very concerned about the possible side-effects of this change.
| modules.""" | ||
| return False | ||
|
|
||
| def isfunction(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change can cause lots of problems to existing users. Because inspect is already used in quite complex code, which uses introspection of different objects in a very specific way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no functional change in isfunction. I just thought it's good to clarify that only true Python functions are matched.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about functions defined in PyPy, RustPython, and others? What about PyO3 functions? What about other possible binary ways of defining functions?
There is no functional change in
isfunction
This would need a proof with real data, unfortunatelly :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no functional change in isfunction
This would need a proof with real data, unfortunatelly :(
The github review interface might be confusing here: the only change in isfunction is in the docstring. The "real" change is in getfile and findsource.
I wasn't sure how to add a proper test. There doesn't seem to be any cython files in the repo. What I could do of course would be to create a dummy object with
Could you please expand what kind of side-effects you would expect? Why would it lead to a problem if |
inspect to support Cythoninspect to support Cython
Misc/NEWS.d/next/Core_and_Builtins/2025-03-23-14-13-20.gh-issue-131628.M9Q06m.rst
Outdated
Show resolved
Hide resolved
…e-131628.M9Q06m.rst Co-authored-by: Nicolas Trangez <[email protected]>
Currently,
getfileandfindsourceare not able to return the correct source (file) for Cython methods since it usesisfunctionwhich returns only true for true Python functions.Here, we change this to a check for
__code__so that it works for Cython functions as well.inspect.getfile#131628