Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source code generation bugs #22

Open
aniskoff opened this issue Aug 4, 2020 · 0 comments
Open

source code generation bugs #22

aniskoff opened this issue Aug 4, 2020 · 0 comments

Comments

@aniskoff
Copy link

aniskoff commented Aug 4, 2020

Hi! I was using astmonkey for the purposes of my project and notice several bugs in code generation (visitors.to_source) function. The code snippets below (the original code and the code generated from the original's AST) illustrate the problems:

  1. visitors.to_source doesn't distinguish single-quoted strings (like 'hello') from double-quoted strings (like "hello"). This is a problem because statements like 'this is "double quotes" inside single quotes' won't be proceeded correctly.
    E.g. code generated from AST of the code below
s = 'this is "double quotes" inside single quotes'

will become

'this is 'double quotes' inside single quotes'

and that will be a SyntaxError.

  1. visitors.to_source doesn't account async's in comprehension's (like [i async for i in some_iterable])
[i async for i in some_iterable]

will become

[i for i in some_iterable]

i.e. async is lost.

  1. visitors.to_source doesn’t support AnnAssign (annotated assignment like a: int = 1 ) which was introduced in Python 3.6
a: int = 1

will become

aint2

and that will be a SyntaxError.

  1. visitors.to_source works incorrectly on more than one decorator (both for functions and classes). Example with function:
@dec1
@dec2
def foo():
	pass

will become

@dec1@dec2
def f():pass

and that will be a SyntaxError.

  1. visitors.to_source still works incorrectly on else in try except stmt. Example:
try:
    do_smth1()
except SomeError as e:
    do_smth2()
else:
    do_smth3()
finally:
    do_smth4() 

will become

try:
    do_smth1()
except SomeError as e:
    do_smth2()
finally:
    
    
    do_smth4()
    l += 2else:do_smth3()

and that will be a SyntaxError.

Best regards,
Nick

@aniskoff aniskoff changed the title source code generation bug's source code generation bugs Aug 4, 2020
jepler added a commit to jepler/astmonkey that referenced this issue Sep 25, 2022
This was reported in mutpy#22 as not working, but it seems OK now
jepler added a commit to jepler/astmonkey that referenced this issue Sep 25, 2022
This was reported broken in mutpy#22
jepler added a commit to jepler/astmonkey that referenced this issue Sep 25, 2022
This was reported in mutpy#22 as not working, but it seems OK now
jepler added a commit to jepler/astmonkey that referenced this issue Sep 25, 2022
This was reported broken in mutpy#22
jepler added a commit to jepler/astmonkey that referenced this issue Sep 25, 2022
This was reported broken in mutpy#22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant