Skip to content

bpo-46820: Fix a SyntaxError in a numeric literal followed by "not in" #31479

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2022

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Feb 21, 2022

Fix parsing a numeric literal immediately (without spaces) followed by
"not in" keywords, like in "1not in x". Now the parser only emits
a warning, not a syntax error.

https://bugs.python.org/issue46820

Fix parsing a numeric literal immediately (without spaces) followed by
"not in" keywords, like in "1not in x". Now the parser only emits
a warning, not a syntax error.
Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks for the quick fix @serhiy-storchaka ! 🎉

check("0not in x")
check("1.not in x")
check("1e3not in x")
check("1jnot in x")
Copy link
Member

Choose a reason for hiding this comment

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

Small nit: At this point maybe we want to make these strings dynamically:

for infix in ["and", "or", "in", "not in"]:
        check(f"0xf{infix} x")
        check(f"0o7{infix} x")
        check(f"0b1{infix} x")
        check(f"9{infix} x")
        check(f"0{infix} x")
        check(f"1.{infix} x")
        check(f"1e3{infix} x")
        check(f"1j{infix} x")

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll rewrite tests in a separate PR.

check("0not in x")
check("1.not in x")
check("1e3not in x")
check("1jnot in x")
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a test with an underscore literal, just for completeness' sake?

Suggested change
check("1jnot in x")
check("1jnot in x")
check("1_000not in x")

@serhiy-storchaka serhiy-storchaka merged commit 090e5c4 into python:main Feb 22, 2022
@miss-islington
Copy link
Contributor

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

@serhiy-storchaka serhiy-storchaka deleted the literal-not-in branch February 22, 2022 07:51
@bedevere-bot
Copy link

GH-31493 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Feb 22, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 22, 2022
pythonGH-31479)

Fix parsing a numeric literal immediately (without spaces) followed by
"not in" keywords, like in "1not in x". Now the parser only emits
a warning, not a syntax error.
(cherry picked from commit 090e5c4)

Co-authored-by: Serhiy Storchaka <[email protected]>
@pxeger
Copy link
Contributor

pxeger commented Feb 22, 2022

xref #31494

serhiy-storchaka added a commit that referenced this pull request Feb 22, 2022
GH-31479) (GH-31493)

Fix parsing a numeric literal immediately (without spaces) followed by
"not in" keywords, like in "1not in x". Now the parser only emits
a warning, not a syntax error.
(cherry picked from commit 090e5c4)

Co-authored-by: Serhiy Storchaka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants