bpo-42116: Fix inspect.getsource handling of trailing comments#23630
Conversation
|
ISTM that we should only include comments indented at least as much as the function's inner indentation, rather than anything more than the outer indentation. For example, in the following case, I would not expect the comment to be considered part of the function's code: def foo():
print("Hello")
# a comment? |
That's a good idea. It will make the code simpler, and we're talking about a non-PEP8 compliant edge case anyway. |
taleinat
left a comment
There was a problem hiding this comment.
Looks good! Just one minor suggestion for one of the test cases.
|
Thanks @iritkatriel for the PR, and @taleinat for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9. |
…nGH-23630) (cherry picked from commit 6e1eec7) Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>
|
GH-23643 is a backport of this pull request to the 3.9 branch. |
…nGH-23630) (cherry picked from commit 6e1eec7) Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>
|
GH-23644 is a backport of this pull request to the 3.8 branch. |
) (cherry picked from commit 6e1eec7) Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>
) (cherry picked from commit 6e1eec7) Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>
https://bugs.python.org/issue42116