[issue44259] lib2to3 does not accept "exec" as name

2021-05-29 Thread Mulugruntz


Mulugruntz  added the comment:

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

--

___
Python tracker 
<https://bugs.python.org/issue44259>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44259] lib2to3 does not accept "exec" as name

2021-05-29 Thread Mulugruntz


Mulugruntz  added the comment:

Traceback (most recent call last):
  File "/Users/sgiffard/Library/Application 
Support/JetBrains/PyCharm2020.3/scratches/scratch_24.py", line 9, in 
driver.parse_string("""class C:\ndef 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))

--

___
Python tracker 
<https://bugs.python.org/issue44259>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44259] lib2to3 does not accept "exec" as name

2021-05-28 Thread Mulugruntz


New submission from Mulugruntz :

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:

```python
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)

```

```shell
It works: def fname(): pass
It fails: def exec(): pass
It fails: 
class C:
def exec(self): pass
```

--
components: 2to3 (2.x to 3.x conversion tool)
messages: 394650
nosy: mulugruntz
priority: normal
severity: normal
status: open
title: lib2to3 does not accept "exec" as name
type: crash
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue44259>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com