Skip to content

lib2to3 does not accept "exec" as name #88425

Closed

Description

@Mulugruntz
BPO 44259
Nosy @terryjreedy, @iritkatriel, @Mulugruntz
Superseder
  • bpo-45544: Close 2to3 issues and list them here
  • 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-10-20.22:52:24.270>
    created_at = <Date 2021-05-28.10:19:27.232>
    labels = ['type-bug', 'expert-2to3', '3.9']
    title = 'lib2to3 does not accept "exec" as name'
    updated_at = <Date 2021-10-20.22:52:24.270>
    user = 'https://github.com/Mulugruntz'

    bugs.python.org fields:

    activity = <Date 2021-10-20.22:52:24.270>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-20.22:52:24.270>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2021-05-28.10:19:27.232>
    creator = 'mulugruntz'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44259
    keywords = []
    message_count = 5.0
    messages = ['394650', '394684', '394721', '394722', '401338']
    nosy_count = 3.0
    nosy_names = ['terry.reedy', 'iritkatriel', 'mulugruntz']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = 'behavior'
    url = 'https://bugs.python.org/issue44259'
    versions = ['Python 3.9']

    Activity

    1. Mulugruntz commented on May 28, 2021

      Mulugruntzmannequin
      MannequinAuthor

      I was trying to use https://github.com/NiklasRosenstein/pydoc-markdown to generate some doc for https://github.com/Mulugruntz/aiosubprocess

      It was failing and for a while I thought I was doing something wrong. But when I did dig deeper, I realized that it was failing because I has a method named "exec".

      The reason why I want to use "exec" is to make it obvious whether I'm executing the subprocess in shell mode or not (there's also a "shell" method).

      As we can see here https://docs.python.org/3.9/reference/lexical_analysis.html#keywords

      "exec" is not reserved.

      Moreover, it's pretty counterintuitive that the code parses and runs correctly (cpython 3.9.5) but the lib2to3 parser crashes.

      See below a working example:

      from lib2to3 import pygram, pytree
      from lib2to3.pgen2 import driver
      from lib2to3.pgen2.parse import ParseError
      
      grammar = pygram.python_grammar.copy()
      driver = driver.Driver(grammar, convert=pytree.convert)
      
      strings = [
          "def fname(): pass",
          "def exec(): pass",
          """
      class C:
          def exec(self): pass""",
      ]
      
      for s in strings:
          try:
              driver.parse_string(s + '\n')
          except ParseError as pe:
              print("It fails:", s)
          else:
              print("It works:", s)
      It works: def fname(): pass
      It fails: def exec(): pass
      It fails: 
      class C:
          def exec(self): pass
    2. terryjreedy commented on May 28, 2021

      @terryjreedy
      Member

      'exec' was a keyword in 2.x, but that should not matter in 3.9. What OS? Did you get an actual crash (core dump on *nix), or a python exception and traceback (not a crash)? If the latter, copy and paste it.

    3. Mulugruntz commented on May 29, 2021

      Mulugruntzmannequin
      MannequinAuthor
      Traceback (most recent call last):
        File "/Users/sgiffard/Library/Application Support/JetBrains/PyCharm2020.3/scratches/scratch_24.py", line 9, in <module>
          driver.parse_string("""class C:\n    def exec(self): pass\n""")
        File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib2to3/pgen2/driver.py", line 103, in parse_string
          return self.parse_tokens(tokens, debug)
        File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib2to3/pgen2/driver.py", line 71, in parse_tokens
          if p.addtoken(type, value, (prefix, start)):
        File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib2to3/pgen2/parse.py", line 162, in addtoken
          raise ParseError("bad input", type, value, context)
      lib2to3.pgen2.parse.ParseError: bad input: type=1, value='exec', context=(' ', (2, 8))
    4. Mulugruntz commented on May 29, 2021

      Mulugruntzmannequin
      MannequinAuthor

      Sorry, I forgot to mention:
      macOS Mojave 10.14.5 (18F132)

    5. iritkatriel commented on Sep 7, 2021

      @iritkatriel
      Member

      Changing type as crash typically refers to segfault and not an exception.

    6. added
      type-bugAn unexpected behavior, bug, or error
      and removed
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Sep 7, 2021
    7. transferred this issue fromon Apr 10, 2022
    8. Mulugruntz commented on Apr 15, 2022

      @Mulugruntz
      ContributorAuthor

      Hi @iritkatriel , do we know the readon why it was closed?

    9. iritkatriel commented on Apr 15, 2022

      @iritkatriel
      Member

      lib2to3 is deprecated, core devs will not be working on it anymore.

    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

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions