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

Parsing error #4

Open
ghost opened this issue Apr 12, 2022 · 4 comments
Open

Parsing error #4

ghost opened this issue Apr 12, 2022 · 4 comments

Comments

@ghost
Copy link

ghost commented Apr 12, 2022

OS: Windows 10 21H2
Python: Python 3.10.4

Steps:

  • pip install pyquotes

example.py

'''
Example File
'''

A = "This is a test string."
B = 'This is a test string.'
C = "This isn't a test string, or is it?"
D = f"{A}{B}{C}"
E = f'{A}{B}{C}'
  • pyquotes example.py
  • pyquotes --check example.py
  • pyquotes -D example.py
  • pyquotes -D --check example.py

All fail with the error

  File "C:\Python310\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'

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.

@ThiefMaster
Copy link
Owner

Works fine for me... (tested on Python 3.9 though)

@ghost
Copy link
Author

ghost commented Apr 12, 2022

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)

@ThiefMaster
Copy link
Owner

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.

@ghost
Copy link
Author

ghost commented Apr 12, 2022

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.

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

No branches or pull requests

1 participant