bpo-46873: Fix inspect.getsource - Count parentheses open/close in decorators#31605
bpo-46873: Fix inspect.getsource - Count parentheses open/close in decorators#31605ahopkins wants to merge 1 commit intopython:mainfrom
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
|
See also #21425. Seems to be a duplicate, sorry I didn't find this earlier. |
DISCLAIMER: First time contribution to cPython itself. I have read thru the contribution guide, but please LMK if I am missing anything.
This PR fixes an issue where calls inside of a lambda passed to a decorator can prematurely breakout of the current code block when using
inspect.getsource(and lower level funcs).Prior to this PR, the following code would produce an unexpected result (only getting the decorator line of the source code).
Result:
This appears to happen because
BlockFinder.tokeneaterwould naively close a decorator after encountering a closing patentheses:). As stated in the bug report:The change that I made moves
BlockFinder.decoratorhasargsto a computed property so that it should at least still be readable without being a breaking change. Please let me know if this (and the change that it introduces) is an acceptable solution.Also, I opted to make a new
inspect_fodder3.pybecause the alternative (while trying to keep like-code together) meant redoing all of the numbering of...fodder2.pyand a significant number of tests. This seemed a far nicer solution to not have to touch a significant majority of the inspect module tests. Happy to hear if this is acceptable.https://bugs.python.org/issue46873