berkerpeksag / astor

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

AttributeError: 'str' object has no attribute '__code__' #148

Closed zaoqi closed 5 years ago

zaoqi commented 5 years ago
>>> astor.code_to_ast('a={}')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/zaoqi/.local/lib/python3.7/site-packages/astor/file_util.py", line 98, in __call__
    key = self.get_file_info(codeobj)
  File "/home/zaoqi/.local/lib/python3.7/site-packages/astor/file_util.py", line 87, in get_file_info
    func_code = codeobj.__code__
AttributeError: 'str' object has no attribute '__code__'
berkerpeksag commented 5 years ago

Thank you for your report. As "code" in code_to_ast() implies, it expects a code object instead of a str object. However, I'd be happy to improve code_to_ast() documentation and exception message. Feel free to share your suggestions!