PyCQA / baron

IDE allow you to refactor code, Baron allows you to write refactoring code.
http://baron.pycqa.org
GNU Lesser General Public License v3.0
289 stars 50 forks source link

Return annotations #147

Closed RedKhan closed 5 years ago

RedKhan commented 5 years ago

Hi guys, I ran into a problem where Baron interprets the "-" in the "->" of a function's return annotation as a minus instead of as part of an arrow.

def foo() -> int: return 3

baron.parser.ParsingError: Error, got an unexpected token MINUS here: 1 def foo() -<---- here The token MINUS should be one of those: COLON

Very cool project by the way; would be nice to use something like RB in combination with support for annotations to enable some proper static analysis of functions, maybe even hijack some ideas from Haskell.

lordmauve commented 5 years ago

Cannot reproduce with baron==0.9:

>>> baron.parse('def foo() -> int: return 3')
[{'type': 'def', 'async': False, 'return_annotation': {'type': 'name', 'value': 'int'}, 'return_annotation_first_formatting': [{'type': 'space', 'value': ' '}], 'return_annotation_second_formatting': [{'type': 'space', 'value': ' '}], 'async_formatting': [], 'decorators': [], 'name': 'foo', 'first_formatting': [{'type': 'space', 'value': ' '}], 'second_formatting': [], 'third_formatting': [], 'fourth_formatting': [], 'fifth_formatting': [], 'sixth_formatting': [{'type': 'space', 'value': ' '}], 'arguments': [], 'value': [{'type': 'return', 'value': {'type': 'int', 'value': '3', 'section': 'number'}, 'formatting': [{'type': 'space', 'value': ' '}]}, {'type': 'endl', 'value': '\n', 'formatting': [], 'indent': ''}]}]
>>> baron.dumps(_)
'def foo() -> int: return 3\n'
RedKhan commented 5 years ago

uninstalling and re-installing baron to upgrade to 0.9 resolved the problem for me.