GeezerVison is showing github.com — Unexpected Parsing of Numeric Literals Concatenated with Boolean Operators · Issue #87999 · python/cpython
Unexpected Parsing of Numeric Literals Concatenated with Boolean Operators #87999Labels 3.10 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error Description
| BPO |
43833 |
| Nosy |
@gvanrossum, @rhettinger, @cfbolz, @nedbat, @serhiy-storchaka, @zooba, @gvanrossum, @asottile, @pablogsal, @miss-islington, @sco1, @pxeger, @shreyanavigyan, @alimuldal |
| PRs |
bpo-43833: Emit warnings for numeric literals followed by keyword #25466[3.10] bpo-43833: Emit warnings for numeric literals followed by keyword (GH-25466) #26614 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = <Date 2021-06-09.00:25:00.346>
created_at = <Date 2021-04-13.18:27:19.816>
labels = ['interpreter-core', 'type-bug', '3.10']
title = 'Unexpected Parsing of Numeric Literals Concatenated with Boolean Operators'
updated_at = <Date 2021-11-08.13:52:29.794>
user = 'https://github.com/sco1'
bugs.python.org fields:
activity = <Date 2021-11-08.13:52:29.794>
actor = 'pablogsal'
assignee = 'none'
closed = True
closed_date = <Date 2021-06-09.00:25:00.346>
closer = 'pablogsal'
components = ['Interpreter Core']
creation = <Date 2021-04-13.18:27:19.816>
creator = 'sco1'
dependencies = []
files = []
hgrepos = []
issue_num = 43833
keywords = ['patch']
message_count = 27.0
messages = ['390981', '390984', '390988', '390991', '390993', '390995', '390996', '390997', '390998', '390999', '391001', '391002', '391003', '391042', '391050', '391051', '391335', '391336', '391340', '391341', '391351', '391354', '395367', '395368', '396498', '405939', '405949']
nosy_count = 16.0
nosy_names = ['gvanrossum', 'rhettinger', 'Carl.Friedrich.Bolz', 'nedbat', 'Joshua.Landau', 'serhiy.storchaka', 'steve.dower', 'Guido.van.Rossum', 'Anthony Sottile', 'pablogsal', 'miss-islington', 'sco1', 'pxeger', 'shreyanavigyan', 'alimuldal', 'rrauenza']
pr_nums = ['25466', '26614']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue43833'
versions = ['Python 3.10']
Activitysco1 commented on Apr 13, 2021 MannequinAuthor More actions Came across this riddle today:
>>> [0x_for x in (1, 2, 3)]
[15]
Initially I thought this was related to PEP-515 but the unexpected behavior extends to simpler examples as well, such as:
>>> x = 5
>>> 123or x
123
>>> 123and x
5
I'm not familiar enough with C to understand why this is being parsed/tokenized this way, but this seems like it should instead be a SyntaxError. This appears to be fairly old behavior, as the non-underscored version works back to at least 2.7.
And a bonus:
>>> 0x1decade or more
31378142 sco1 commented on Apr 13, 2021 MannequinAuthor More actions Sorry, the bonus, while fun, I don't think is related alimuldal commented on Apr 13, 2021 Several other keywords seem to be affected, including if, else, is, and in cfbolz commented on Apr 13, 2021 It's not just about keywords. Eg '1x' tokenizes too but then produces a syntax error in the parser. Keywords are only special in that they can be used to write syntactically meaningful things with these concatenated numbers. pablogsal commented on Apr 13, 2021 This is know behaviour unfortunately and cannot be changed because of backwards compatibility. miss-islington commented on Jun 8, 2021 pxeger commented on Jun 24, 2021 I would like to note that syntax like this is in heavy use in the Code Golf community (a sport in which the aim is to write the shortest code possible to complete a particular task).
It will be disappointing if it becomes an error and break many past programs (you can search for phrases like 1and, 0for on https://codegolf.stackexchange.com/search?q=0for for examples).
I could understand if this change remains because code golf is not exactly an important thing with serious ramifications, but I think it should be taken in to consideration as a use-case nonetheless. Reacted by FichteFoll, Abbas Yadollahi and Marek Madejski gvanrossum commented on Nov 8, 2021 Do we have a plan for when this will be turned into a non-silent warning and when into an error? pablogsal commented on Nov 8, 2021 Unless I am missing something it should be 3.11 non-silent warning and 3.12 syntax error gvanrossum commented on Apr 25, 2022
Unless I am missing something it should be 3.11 non-silent warning and 3.12 syntax error
Following up: Is this a non-silent warning yet? serhiy-storchaka commented on Apr 25, 2022 It is still DeprecationWarning. added 2 commits that reference this issue on Apr 27, 2022pythongh-87999: Change warning type for numeric literal followed by k… gh-87999: Change warning type for numeric literal followed by keyword (… Rhaxier commented on Nov 17, 2022 I tried the code that is the subject of this issue,
but in the usual IDLE installable from python.org, it doesn't raise anything. It still returns [31].
Further note to @pxeger: Our code-golf answers are normally posted in a specific python version (such as 2 or 3). When it's omitted, we assume it's Python 3, or the Python version that existed when the answer was posted. Besides an easy fix for this issue will be to specify the latest version of Python that allows this bug to be exploited, i.e. if this bug is fixed in, say Python 3.12, we can simply update our answers to say they work in Python versions before 3.12. Otherwise I don't think this bug being fixed will result in issues in executed code. serhiy-storchaka commented on Nov 17, 2022 Please open a new issue for IDLE. Perhaps there is already an open issue for SyntaxWarning in IDLE. Rhaxier commented on Nov 18, 2022 I have opened a new one under BPO 99567. Rhaxier commented on Dec 5, 2022 @pablogsal this comment on my closed issue says otherwise:
In 3.12.0a2+, as of today, this is still just a warning. Duplicate of #82005. Thanks for the current example.
MetadataMetadata3.10 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DevelopmentNo branches or pull requestsIssue actions
|