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

Syntax error on # type: Any after a module import #8655

Closed
Pierre-Sassoulas opened this issue May 4, 2023 · 1 comment
Closed

Syntax error on # type: Any after a module import #8655

Pierre-Sassoulas opened this issue May 4, 2023 · 1 comment
Labels
Duplicate 🐫 Duplicate of an already existing issue

Comments

@Pierre-Sassoulas
Copy link
Member

          Pylint also doesn't like `# type: Any` comments after a module import:
from collections import abc  # type: Any
E0001: Parsing failed: 'invalid syntax (<unknown>, line 1)' (syntax-error)
$ pylint --version
pylint 2.16.2
astroid 2.14.2
Python 3.11.0 (main, Feb 21 2023, 11:59:45) [GCC 12.2.0]

Originally posted by @yilei in #3556 (comment)

@Pierre-Sassoulas Pierre-Sassoulas added Bug 🪲 Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels May 4, 2023
@mbyrnepr2
Copy link
Member

mbyrnepr2 commented May 4, 2023

I think this is the same root-cause as #3556 (python -m ast example.py on that example is also a SyntaxError).

Generally there is a SyntaxError with code using the # type: something syntax corresponding to the ast module class with no type_comment parameter.
For example, we can reproduce the issue with:

cat example.py:

if True: # type: Any
    print("True")

pylint example.py
py:1:18: E0001: Parsing failed: 'invalid syntax (, line 1)' (syntax-error)

python -m ast example.py

  File "example.py", line 1
    if True: # type: Any
                     ^^^
SyntaxError: invalid syntax

@Pierre-Sassoulas Pierre-Sassoulas added Duplicate 🐫 Duplicate of an already existing issue and removed Bug 🪲 Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels May 4, 2023
@Pierre-Sassoulas Pierre-Sassoulas closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

2 participants