Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
gh-137477: Fix inspect.getblock() for generator expressions#137488
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This fixes also inspect.getsourcelines() and inspect.getsource().
Lib/inspect.py Outdated
| self.islambda=True | ||
| self.started=True | ||
| else: | ||
| self.islambda=True |
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.
Could you explain this part a bit to me? What's in the else case? Why isislambda set? I was a bit confused (without testing too much into it) when I read the code because I thought this is definitely not a lambda here.
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.
For def and class we search to the end of the block. For lambda and generator expressions we search to the end of the logical line.self.islambda is used to distinguish between these modes. We could rename it, but this will increase the size of the diff and may break user code that uses this private class, so I leave it for a time.
Although the code can be simplified.
@gaogaotiantian, is it fine to you? |
Sorry I've been travelling the world so not super responsive. Even though I always agree a minimum change is preferred, but This could raise some minor backwards compatibility issues, I agree. I think it can be ignored because it's a non-documented variable in a private class. Another way is to add another variable If the breaking change is really a huge concern to you, I think I can accept a backport with this change, and an immediate rename for |
What name would be good? Anyway, I want to refactor this code in main. There is no justification to use a class -- it may be a simple function taking a stream of tokens. |
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.
Sorry for the delay. I thinksingleline is an acceptable name.
eae9d7d intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…thonGH-137488)This fixes also inspect.getsourcelines() and inspect.getsource().(cherry picked from commiteae9d7d)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sorry,@serhiy-storchaka, I could not cleanly backport this to |
GH-137993 is a backport of this pull request to the3.14 branch. |
Thank you for review,@gaogaotiantian! |
…ons (pythonGH-137488)This fixes also inspect.getsourcelines() and inspect.getsource().(cherry picked from commiteae9d7d)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
GH-137995 is a backport of this pull request to the3.13 branch. |
Uh oh!
There was an error while loading.Please reload this page.
This fixes also inspect.getsourcelines() and inspect.getsource().
inspect.getsourcelines()mishandles multi-line generator expressions #137477