Open ghost opened 2 years ago
Works fine for me... (tested on Python 3.9 though)
Narrowed it down further, although I realize this is a PEP8 violation, it occurs if there is no new line and the last character is a closing quote. (Checked on Python 3.9 to match you)
OK, I'm inclined to say "garbage in, garbage out" (text/code files should ALWAYS contain a trailing linebreak), but if it's not a bug in parso but pyquotes and can be easily fixed I'll accept a PR for it.
Traceback (most recent call last):
File "C:\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Python39\Scripts\pyquotes.exe\__main__.py", line 7, in <module>
File "C:\Python39\lib\site-packages\click\core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "C:\Python39\lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
File "C:\Python39\lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Python39\lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "C:\Python39\lib\site-packages\pyquotes\cli.py", line 89, in main
changed = _process_file(file, config=config)
File "C:\Python39\lib\site-packages\pyquotes\cli.py", line 114, in _process_file
new_code = transform_source(old_code, double_quotes=config.double_quotes)
File "C:\Python39\lib\site-packages\pyquotes\transform.py", line 49, in transform_source
for is_doc, leaf in _iter_strings(tree):
File "C:\Python39\lib\site-packages\pyquotes\transform.py", line 42, in scan
yield from scan(node)
File "C:\Python39\lib\site-packages\pyquotes\transform.py", line 29, in scan
doc_node = parent.get_doc_node()
File "C:\Python39\lib\site-packages\parso\python\tree.py", line 86, in get_doc_node
c = simple_stmt.parent.children
AttributeError: 'NoneType' object has no attribute 'children'
This is the full stack trace, and confirmed it doesn't happen for example if the contents is print("Test")
without a newline.
OS: Windows 10 21H2 Python: Python 3.10.4
Steps:
example.py
All fail with the error
If a
print('Hello, World!')
is added to the file, it behaves as expected.Thank you for your time, this library has saved my many hours.