FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Unexpected Parsing of Numeric Literals Concatenated with Boolean Operators · Issue #87999 · python/cpython · GitHub

Repository navigation

Unexpected Parsing of Numeric Literals Concatenated with Boolean Operators #87999

Closed

Description

mannequin
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']

    Activity

    1. sco1 commented on Apr 13, 2021

      sco1mannequin
      MannequinAuthor

      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
    2. sco1 commented on Apr 13, 2021

      sco1mannequin
      MannequinAuthor

      Sorry, the bonus, while fun, I don't think is related

    3. alimuldal commented on Apr 13, 2021

      alimuldalmannequin
      Mannequin

      Several other keywords seem to be affected, including if, else, is, and in

    4. cfbolz commented on Apr 13, 2021

      cfbolzmannequin
      Mannequin

      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.

    5. pablogsal commented on Apr 13, 2021

      Member

      This is know behaviour unfortunately and cannot be changed because of backwards compatibility.

    6. 26 remaining items

    7. miss-islington commented on Jun 8, 2021

      Contributor

      New changeset eeefa7f by Miss Islington (bot) in branch '3.10':
      bpo-43833: Emit warnings for numeric literals followed by keyword (GH-25466)
      eeefa7f

    8. pxeger commented on Jun 24, 2021

      pxegermannequin
      Mannequin

      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.

    9. gvanrossum commented on Nov 8, 2021

      Member

      Do we have a plan for when this will be turned into a non-silent warning and when into an error?

    10. pablogsal commented on Nov 8, 2021

      Member

      Unless I am missing something it should be 3.11 non-silent warning and 3.12 syntax error

    11. transferred this issue fromon Apr 10, 2022
    12. gvanrossum commented on Apr 25, 2022

      Member

      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?

    13. serhiy-storchaka commented on Apr 25, 2022

      Member

      It is still DeprecationWarning.

    14. added 2 commits that reference this issue on Apr 27, 2022
    15. Rhaxier commented on Nov 17, 2022

      Contributor

      I tried the code that is the subject of this issue,

      [0x1for x in range(10)]

      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.

    16. serhiy-storchaka commented on Nov 17, 2022

      Member

      Please open a new issue for IDLE. Perhaps there is already an open issue for SyntaxWarning in IDLE.

    17. Rhaxier commented on Nov 18, 2022

      Contributor

      I have opened a new one under BPO 99567.

    18. Rhaxier commented on Dec 5, 2022

      Contributor

      @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.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions


        Back | FazBrowse Home | New Git URL