berkerpeksag / astor

Python AST read/write
https://pypi.org/project/astor/
BSD 3-Clause "New" or "Revised" License
810 stars 102 forks source link

'async' and 'await' will become keywords in Python 3.7 #86

Closed berkerpeksag closed 6 years ago

berkerpeksag commented 6 years ago

The following code won't work in Python 3.7:

https://github.com/berkerpeksag/astor/blob/5f189fc5cae9a5c3ca75bc204a8ac9a361b4bcc7/astor/code_gen.py#L311

Full list:

astor/code_gen.py:311:    def visit_FunctionDef(self, node, async=False):
astor/code_gen.py:312:        prefix = 'async ' if async else ''
astor/code_gen.py:325:        self.visit_FunctionDef(node, async=True)
astor/code_gen.py:367:    def visit_For(self, node, async=False):
astor/code_gen.py:369:        prefix = 'async ' if async else ''
astor/code_gen.py:376:        self.visit_For(node, async=True)
astor/code_gen.py:383:    def visit_With(self, node, async=False):
astor/code_gen.py:384:        prefix = 'async ' if async else ''
astor/code_gen.py:395:        self.visit_With(node, async=True)
vodik commented 6 years ago

Do you have a particular solution in mind? Or am I free to adjust this? I don't image its technically part of your public API.

berkerpeksag commented 6 years ago

I'm planning to rename async to is_async. Would you like to submit a PR?

berkerpeksag commented 6 years ago

Also, I wonder if we can drop the async keyword argument and replace

prefix = 'async ' if async else ''

with

prefix = 'async ' if self.get_is_async(node) else ''

in visit_FunctionDef.

vodik commented 6 years ago

Yeah, sure, I can do that.

zackmdavis commented 6 years ago

(Sorry, I should have foreseen that this was going to be a problem in #19)