Skip to content

gh-130775: Allow negative locations in ast - #130795

Merged
sobolevn merged 5 commits into
python:mainfrom
sobolevn:issue-130775
Apr 7, 2025
Merged

gh-130775: Allow negative locations in ast#130795
sobolevn merged 5 commits into
python:mainfrom
sobolevn:issue-130775

Conversation

@sobolevn

@sobolevnsobolevn commented Mar 3, 2025

Copy link
Copy Markdown
Member

@picnixzpicnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we cannot bypass the ast.c layer and directly end up in the assemble.c, then this should be the correct approach (I didn't know where we validate the locations).

Comment on lines +211 to +214
{'lineno': -2, 'col_offset': 0},
{'lineno': 0, 'col_offset': -2},
{'lineno': 0, 'col_offset': -2, 'end_col_offset': -2},
{'lineno': -2, 'end_lineno': -2, 'col_offset': 0},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Off topic: are we already testing that passing a non-int is fine?
  • Maybe test with values that are excessively large (either in + or -) just for overflow checks.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will open a new issue for that, if we don't. Thanks for the idea.

Comment threadPython/ast.c Outdated
Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner
vstinner previously approved these changes Mar 3, 2025

@vstinnervstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I just suggest a shorter test name :-)

Comment threadLib/test/test_ast/test_ast.py Outdated
Comment threadLib/test/test_ast/test_ast.py Outdated
Comment threadPython/assemble.c Outdated
Comment threadPython/ast.c Outdated
Comment threadPython/ast.c Outdated
@vstinner
vstinner dismissed their stale reviewMarch 7, 2025 16:08

I remove my LGTM vote, I didn't notice that -1 value is still allowed. I'm not sure about rejecting values <= -2.

@sobolevn

sobolevn commented Mar 13, 2025

Copy link
Copy Markdown
MemberAuthor

Ok, I followed the idea in #130795 (comment) by @JelleZijlstra and now all negative locations are just allowed. This way we won't have any compat issues and can backport this fix easily.

Thanks a lot, everyone!

@vstinnervstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@sobolevn

Copy link
Copy Markdown
MemberAuthor

Looks like #130627 changed a lot of related things. Digging into it.

@sobolevn
sobolevn merged commit bc5233b into python:mainApr 7, 2025
@sobolevnsobolevn added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Apr 7, 2025
@miss-islington-app

Copy link
Copy Markdown

Thanks @sobolevn for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @sobolevn for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @sobolevn, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker bc5233b6a5cdd8f77a4737ce317f94110869c082 3.12

@miss-islington-app

Copy link
Copy Markdown

Sorry, @sobolevn, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker bc5233b6a5cdd8f77a4737ce317f94110869c082 3.13

@sobolevn

Copy link
Copy Markdown
MemberAuthor

Thanks everyone! 🎉

@sobolevn

Copy link
Copy Markdown
MemberAuthor

I will work on manual backports today.

@sobolevnsobolevn changed the title gh-130775: Validate negative locations in astgh-130775: Allow negative locations in astApr 7, 2025
sobolevn added a commit to sobolevn/cpython that referenced this pull request Apr 7, 2025
…30795)
(cherry picked from commit bc5233b)
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app

Copy link
Copy Markdown

GH-132243 is a backport of this pull request to the 3.13 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.13 bugs and security fixes label Apr 7, 2025
Yhg1s pushed a commit that referenced this pull request Apr 8, 2025
)
(cherry picked from commit bc5233b)
Co-authored-by: Victor Stinner <vstinner@python.org>
sobolevn added a commit to sobolevn/cpython that referenced this pull request Apr 8, 2025
…30795)
(cherry picked from commit bc5233b)
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app

Copy link
Copy Markdown

GH-132260 is a backport of this pull request to the 3.12 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.12 only security fixes label Apr 8, 2025
Yhg1s pushed a commit that referenced this pull request Apr 8, 2025
)
(cherry picked from commit bc5233b)
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@sobolevn@cfbolz@vstinner@JelleZijlstra@iritkatriel@picnixz