facebookincubator / Bowler

Safe code refactoring for modern Python.
https://pybowler.io/
MIT License
1.53k stars 89 forks source link

Failed to parse on **(expr) without parens #74

Open thatch opened 5 years ago

thatch commented 5 years ago

This appears to be valid in 3.6, 3.7, and 3.8.0a2:

def func(**kwargs):
    print(kwargs)

x = {'a': '1'}
func(**x or {})

Bowler can't parse it, I'm wondering if there is a fissix issue? We should also show the error near "except ParseError" in bowler/tool.py.

thatch commented 5 years ago

This appears to be an issue with lib2to3 on all three versions mentioned above:

from lib2to3.pgen2 import driver
from lib2to3 import pygram, pytree

def main():
    with open("t.py") as input:
        data = input.read()
    d = driver.Driver(
        pygram.python_grammar_no_print_statement,
        convert=pytree.convert,
    )
    tree = d.parse_string(data)
    print(tree)

if __name__ == '__main__':
    main()
amyreese commented 5 years ago

https://github.com/python/cpython/pull/12702 and https://github.com/python/cpython/pull/12703 opened upstream for this

zsol commented 5 years ago

This has been fixed in blib2to3 in Black. Maybe I should split it out into its own module, seeing how there's not much interest in backporting changes like https://github.com/python/cpython/pull/6586 and https://github.com/python/cpython/pull/6588