Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedAug 6, 2025
edited by bedevere-appbot
Loading

This fixes also inspect.getsourcelines() and inspect.getsource().

This fixes also inspect.getsourcelines() and inspect.getsource().
self.islambda=True
self.started=True
else:
self.islambda=True

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.

Copy link
MemberAuthor

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.

@serhiy-storchaka
Copy link
MemberAuthor

@gaogaotiantian, is it fine to you?

@gaogaotiantian
Copy link
Member

Sorry I've been travelling the world so not super responsive. Even though I always agree a minimum change is preferred, butislambda is still very confusing to me. I know you added a comment, but that does not make it super clear - the logic between generator and lambda is still vague. Let's say in the future we somehow have a third case, do we still call itislambda? I think we should give it a better name now, a name that actually represents what it means - end at logic line instead of the end of block.

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 variableisgenerator, which will fix the issue, keep the backwards compatibility but make the diff even larger.

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 formain, will that be a good compromise that you think is proper?

@serhiy-storchaka
Copy link
MemberAuthor

What name would be good?singleline?logicalline?singlelogicalline?multiline=False?

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.

Copy link
Member

@gaogaotiantiangaogaotiantian left a 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.

serhiy-storchaka reacted with thumbs up emoji
@serhiy-storchakaserhiy-storchaka merged commiteae9d7d intopython:mainAug 20, 2025
47 of 48 checks passed
@miss-islington-app
Copy link

Thanks@serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestAug 20, 2025
…thonGH-137488)This fixes also inspect.getsourcelines() and inspect.getsource().(cherry picked from commiteae9d7d)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@miss-islington-app
Copy link

Sorry,@serhiy-storchaka, I could not cleanly backport this to3.13 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker eae9d7de1c45a64076a926d53672823e6ae1777d 3.13

@bedevere-app
Copy link

GH-137993 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelAug 20, 2025
@serhiy-storchaka
Copy link
MemberAuthor

Thank you for review,@gaogaotiantian!

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull requestAug 20, 2025
…ons (pythonGH-137488)This fixes also inspect.getsourcelines() and inspect.getsource().(cherry picked from commiteae9d7d)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app
Copy link

GH-137995 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelAug 20, 2025
serhiy-storchaka added a commit that referenced this pull requestAug 20, 2025
…H-137488) (GH-137995)This fixes also inspect.getsourcelines() and inspect.getsource().(cherry picked from commiteae9d7d)
vstinner pushed a commit that referenced this pull requestOct 7, 2025
…H-137488) (#137993)gh-137477: Fix inspect.getblock() for generator expressions (GH-137488)This fixes also inspect.getsourcelines() and inspect.getsource().(cherry picked from commiteae9d7d)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@gaogaotiantiangaogaotiantiangaogaotiantian approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@serhiy-storchaka@gaogaotiantian

[8]ページ先頭

©2009-2025 Movatter.jp