bpo-38854: Adjust inspect.getsource to properly extract source for decorated functions#17374
Closed
PCManticore wants to merge 1 commit intopython:masterfrom
Closed
Conversation
inspect.getsource to properly extract source for decorated functionsinspect.getsource to properly extract source for decorated functions
Contributor
|
Loosely related to gh-8602, in case we want to get multiple inspect fixes in the same release |
eric-wieser
reviewed
Nov 25, 2019
eric-wieser
reviewed
Nov 25, 2019
eric-wieser
approved these changes
Nov 25, 2019
Contributor
eric-wieser
left a comment
There was a problem hiding this comment.
Code looks like it correctly covers the intended case, although is probably still not foolproof.
Contributor
Author
|
Thanks for the review @eric-wieser ! I'll submit those changes shortly, in the meantime, do let me know if this solution needs to handle other edge cases. |
a66ecb6 to
bd6fba7
Compare
Contributor
Author
|
The CI documentation job failure is a fluke, I can't retry the job though. |
… functions When the arguments to a decorator contain any additional parentheses, ``inspect.BlockFinder`` was misinterpreting the closing paren as the closing paren of the decorator, leading to a clipped result of the extracted source of a function. Instead of assuming the closing paren closes the decorator call itself, we keep track of all the parentheses in a new stack, making sure to unset the decorator context once we consumed all of them.
bd6fba7 to
aeaf16c
Compare
Contributor
|
@PCManticore |
3 tasks
blueyed
reviewed
Jul 9, 2020
| self.indecorator = False | ||
| self.decoratorhasargs = False | ||
| else: | ||
| self.decoratorparens.append(token) |
Contributor
There was a problem hiding this comment.
(Why) Is it necessary to keep track of the tokens?
(came here via #21425, which only uses a count)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the arguments to a decorator call contain additional parentheses
from scalar values such as tuples or additional function calls,
inspect.BlockFinderis misinterpreting the closing paren as the closingparen of the decorator call itself, leading to a clipped result of the extracted
source of a function.
Instead of assuming the closing paren closes the decorator call itself, we keep
track of all the parentheses in a new stack, making sure to unset the decorator
context once we consumed all of them.
https://bugs.python.org/issue38854