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

Support for PEP 695 - E0001 should not fire on 3.12 generics syntax #9217

Closed
rbobillot opened this issue Nov 4, 2023 · 4 comments
Closed
Labels
Invalid Not a bug, already exists or already fixed python 3.12

Comments

@rbobillot
Copy link

Current problem

I am using Python 3.12 generics new syntax PEP-695 in a project, such as:

def get_users[I](skip: int | None, limit: int | None, inventory: I) -> list[User]:
    return repo_handler.get_users(skip, limit, inventory)

Unfortunately, pylint cannot parse it and the following error occurs:

repository.py:18:8: E0001: Parsing failed: 'invalid syntax (<unknown>, line 18)' (syntax-error)

I even tried with the basic syntax:

def head[T](args: Iterable[T]) -> T:
    return args[0]

But the same error occurs

Desired solution

For now, I'd say it should give a more ad-hoc error (rather than invalid syntax), so we could at least skip it.
Ideally it should handle this new syntax.

Additional context

I didn't find this issue among pylint open issues.

Though, I found it here in mypy issues
For now, they did a little workaround, saying they cant handle PEP-695 yet,
but it seems that a lot of work needs to be done to handle it.

Unfortunately I'm not sure I have enough free time yet to open a PR and try to fix those issues

@rbobillot rbobillot added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Nov 4, 2023
@Pierre-Sassoulas Pierre-Sassoulas added python 3.12 Bug 🪲 and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 4, 2023
@jacobtylerwalls
Copy link
Member

Hi 👋🏻. What python interpreter are you using to run pylint? Below 3.12?

@jacobtylerwalls jacobtylerwalls added Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling and removed Bug 🪲 labels Nov 4, 2023
@Pierre-Sassoulas
Copy link
Member

Hmm yeah, I reproduced on 3.11, but a 3.11 interpreter is supposed to have this result.

@rbobillot
Copy link
Author

rbobillot commented Nov 4, 2023

I use the 3.12 interpreter (via pyenv):

$ pylint --version

pylint 3.0.2
astroid 3.0.1
Python 3.12.0 (main, Nov  4 2023, 03:02:50) [GCC 11.4.0]

Hi 👋🏻. What python interpreter are you using to run pylint? Below 3.12?

@jacobtylerwalls
Copy link
Member

Thanks for providing the output of pylint --version. This is the only report we have of 3.12 interpreters not parsing the new syntax. (We've had multiple reporters report subtler issues about pylint's static analysis of these correctly parsed constructs, instead.) In other words, pylint/astroid wraps python's AST parser, so I find this behavior surprising--I'd suggest checking for non-obvious things, like pylint being invoked differently between runs, or differences between your local setup and CI.

From your first error message, it also seems pylint is being executed on an interpreter on 3.10 or below, because in 3.11 I would expect a more fine-grained error message (expected '('):

% python3.12 -m pylint b.py
************* Module b
b.py:1:0: C0114: Missing module docstring (missing-module-docstring)
b.py:1:0: C0116: Missing function or method docstring (missing-function-docstring)
b.py:1:76: E0602: Undefined variable 'User' (undefined-variable)
b.py:1:14: C0103: Variable name "I" doesn't conform to snake_case naming style (invalid-name)
b.py:2:11: E0602: Undefined variable 'repo_handler' (undefined-variable)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

% python3.11 -m pylint b.py
************* Module b
b.py:1:14: E0001: Parsing failed: 'expected '(' (<unknown>, line 1)' (syntax-error)

% python3.10 -m pylint b.py
************* Module b
b.py:1:14: E0001: Parsing failed: 'invalid syntax (<unknown>, line 1)' (syntax-error)

@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale Nov 5, 2023
@jacobtylerwalls jacobtylerwalls added Invalid Not a bug, already exists or already fixed and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid Not a bug, already exists or already fixed python 3.12
Projects
None yet
Development

No branches or pull requests

3 participants