GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-43833: Emit warnings for numeric literals followed by keyword by serhiy-storchaka · Pull Request #25466 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Apr 18, 2021 •
edited by miss-islington
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Emit a deprecation warning if the numeric literal is immediately followed by
one of keywords: and, else, for, if, in, is, or. Raise a syntax error with
more informative message if it is immediately followed by other keyword or
identifier.

https://bugs.python.org/issue43833

Automerge-Triggered-By: GH:pablogsal

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
bpo-43833: Emit warnings for numeric literals followed by keyword
56ae489
Emit a deprecation warning if the numeric literal is immediately followed by
one of keywords: and, else, for, if, in, is, or. Raise a syntax error with
more informative message if it is immediately followed by other keyword or
identifier.
@serhiy-storchaka
serhiy-storchaka requested review from gvanrossum and pablogsal April 18, 2021 15:12
@serhiy-storchaka
serhiy-storchaka requested a review from lysnikolaou as a code owner April 18, 2021 15:12
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Apr 18, 2021
@bedevere-bot bedevere-bot added the awaiting core review label Apr 18, 2021
@pablogsal

pablogsal commented Apr 18, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

I am not a fan of this solution as this is coupling the tokenizer and the grammar, which is a known problematic behaviour.

In particular, I don't like the fact that we need to manually check against every keyword explicitly.

Cannot we just error if we find any character that is not a whitespace or a valid numeric literal?

We should try to fix this in a way they is keyword-agnostic

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Apr 18, 2021

Copy link
Copy Markdown
Member Author

Checking against the list of valid keywords is a temporary code. It is because we want to do gradual deprecation and only emit a warning for currently valid code. At the end, there will be only syntax error and no list of keywords.

If emit a warning unconditionally, this will break some tests for invalid numeric literals (test_bad_numerical_literals in test_grammar.py and test_literals_with_leading_zeroes in test_compile.py). Some test cases will produce warning and then error, so we would need to rewrite these tests significantly, and several releases later after converting warnings to error restore original tests. Double warning-error can also confuse users.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented Apr 18, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Checking against the list of valid keywords is a temporary code. It is because we want to do gradual deprecation and only emit a warning for currently valid code. At the end, there will be only syntax error and no list of keywords.

If emit a warning unconditionally, this will break some tests for invalid numeric literals (test_bad_numerical_literals in test_grammar.py and test_literals_with_leading_zeroes in test_compile.py). Some test cases will produce warning and then error, so we would need to rewrite these tests significantly, and several releases later after converting warnings to error restore original tests. Double warning-error can also confuse users.

Thanks for the clarification. Could you add some comments regarding this plans to the source code of the change to make sure this context is there when reading the code?

In that case I assume that the main thing to do here is to all agree on the plan.

I personally find the plan reasonable so I'm on board, but I would go directly to SyntaxWarning and in 1 or 2 releases making it a SyntaxError.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Apr 18, 2021

Copy link
Copy Markdown
Member Author

Sure. I added a comment in verify_end_of_number(), but seems it is not enough. I'll expand by adding explanation of the intention of this behavior.

As for SyntaxWarning vs DeprecationWarning, we still emit DeprecationWarning for invalid character escapes (like in "C:\Program Files"). Initially SyntaxWarning was emitted, but after public discussion it was changed to DeprecationWarning.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka added 2 commits April 18, 2021 22:00
@serhiy-storchaka
Improve comment.
7185f45
@serhiy-storchaka
Merge branch 'main' into end-of-numeric-literal
7caff32
@serhiy-storchaka

serhiy-storchaka commented Jun 7, 2021

Copy link
Copy Markdown
Member Author

@pablogsal, do you want to add these warnings in 3.10 or 3.11 if add them at all?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented Jun 7, 2021

Copy link
Copy Markdown
Member

@pablogsal, do you want to add these warnings in 3.10 or 3.11 if add them at all?

I would like them to be included in Python 3.10 so we can make them illegal sooner. What do you think?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pablogsal
pablogsal approved these changes Jun 8, 2021
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Jun 8, 2021
@pablogsal pablogsal added the needs backport to 3.10 label Jun 8, 2021
pablogsal
pablogsal reviewed Jun 8, 2021
View reviewed changes
Comment thread Doc/whatsnew/3.10.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
Update Doc/whatsnew/3.10.rst
f9ffba0
@pablogsal pablogsal added the 🤖 automerge label Jun 8, 2021
@miss-islington

miss-islington commented Jun 8, 2021

Copy link
Copy Markdown
Contributor

@serhiy-storchaka: Status check is done, and it's a success ✅ .

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington
miss-islington merged commit 2ea6d89 into python:main Jun 8, 2021
@miss-islington

miss-islington commented Jun 8, 2021

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label Jun 8, 2021
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 8, 2021
@serhiy-storchaka @miss-islington
bpo-43833: Emit warnings for numeric literals followed by keyword (py…
6e70771
…thonGH-25466)

Emit a deprecation warning if the numeric literal is immediately followed by
one of keywords: and, else, for, if, in, is, or. Raise a syntax error with
more informative message if it is immediately followed by other keyword or
identifier.

Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit 2ea6d89)

Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-bot

bedevere-bot commented Jun 8, 2021

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 label Jun 8, 2021
miss-islington added a commit that referenced this pull request Jun 8, 2021
@miss-islington @serhiy-storchaka
bpo-43833: Emit warnings for numeric literals followed by keyword (GH…
eeefa7f
…-25466)

Emit a deprecation warning if the numeric literal is immediately followed by
one of keywords: and, else, for, if, in, is, or. Raise a syntax error with
more informative message if it is immediately followed by other keyword or
identifier.

Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit 2ea6d89)

Co-authored-by: Serhiy Storchaka <[email protected]>
@pablogsal pablogsal mentioned this pull request Jul 18, 2021
[3.10] Correct the order of regen-abidump #27228
Closed
@sco1 sco1 mannequin mentioned this pull request Apr 25, 2022
Unexpected Parsing of Numeric Literals Concatenated with Boolean Operators #87999
Closed
@serhiy-storchaka
serhiy-storchaka deleted the end-of-numeric-literal branch January 28, 2024 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pablogsal pablogsal pablogsal approved these changes
@gvanrossum gvanrossum Awaiting requested review from gvanrossum
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@serhiy-storchaka @pablogsal @miss-islington @bedevere-bot @the-knights-who-say-ni
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.