You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Decorator with paren tokens in arguments breaks inspect.getsource #83035
Turns out this was a bug in inspect.BlockFinder which is responsible for extracting out the source code from a given block. This class was considering ")" inside a decorator call as closing the decorator itself, even when the decorator call was accepting additional arguments that needed parentheses, such as function calls or tuples.
Activity
crusaderky commentedon Nov 19, 2019
Python 3.7.5 and 3.8.0
A decorator causes inspect.getsource() to return clipped output:
Output:
Expected output:
These changes to the decorator parameters cause the problem to disappear:
@foo({}, defaultdict(lambda: 1))@foo(dict(), defaultdict(list))PCManticore commentedon Nov 25, 2019
Thanks for the report!
Turns out this was a bug in
inspect.BlockFinderwhich is responsible for extracting out the source code from a given block. This class was considering ")" inside a decorator call as closing the decorator itself, even when the decorator call was accepting additional arguments that needed parentheses, such as function calls or tuples.Just submitted a PR #17374 to address this issue.
[-]Decorator breaks inspect.getsource[/-][+]Decorator with paren tokens in arguments breaks inspect.getsource[/+]pythongh-83035: handle decorator with nested parens in inspect.getsource
carljm commentedon Nov 21, 2022
Looks like there have been three PRs here already, but all of them seem to be incomplete and/or abandoned. Opened a new one: #99654
gh-83035: handle decorator with nested parens in inspect.getsource (#…
pythongh-83035: handle decorator with nested parens in inspect.getsou…
pythongh-83035: handle decorator with nested parens in inspect.getsou…
pythongh-83035: handle decorator with nested parens in inspect.getsou…
gh-83035: handle decorator with nested parens in inspect.getsource (G…
gh-83035: handle decorator with nested parens in inspect.getsource (G…
AlexWaygood commentedon Dec 7, 2022
Fixed and backported. Thanks @carljm! 🎉