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

Fix used-before-assignment FP for generic type syntax (Py 3.12) #9150

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9110.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix ``used-before-assignment`` false positive for generic type syntax (PEP 695, Python 3.12).

Closes #9110
3 changes: 3 additions & 0 deletions pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
nodes.Expr,
nodes.Return,
nodes.Match,
nodes.TypeAlias,
)


Expand Down Expand Up @@ -2329,6 +2330,8 @@ def _maybe_used_and_assigned_at_once(defstmt: nodes.Statement) -> bool:
return any(case.guard for case in defstmt.cases)
if isinstance(defstmt, nodes.IfExp):
return True
if isinstance(defstmt, nodes.TypeAlias):
return True
if isinstance(defstmt.value, nodes.BaseContainer):
return any(
VariablesChecker._maybe_used_and_assigned_at_once(elt)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies = [
# Also upgrade requirements_test_min.txt.
# Pinned to dev of second minor update to allow editable installs and fix primer issues,
# see https://github.com/pylint-dev/astroid/issues/1341
"astroid>=3.0.0,<=3.1.0-dev0",
"astroid>=3.0.1,<=3.1.0-dev0",
"isort>=4.2.5,<6",
"mccabe>=0.6,<0.8",
"tomli>=1.1.0;python_version<'3.11'",
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_min.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.[testutils,spelling]
# astroid dependency is also defined in pyproject.toml
astroid==3.0.0 # Pinned to a specific version for tests
astroid==3.0.1 # Pinned to a specific version for tests
typing-extensions~=4.8
py~=1.11.0
pytest~=7.4
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/u/used/used_before_assignment_py312.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""used-before-assignment re: python 3.12 generic typing syntax (PEP 695)"""

from typing import Callable
type Point[T] = tuple[T, ...]
type Alias[*Ts] = tuple[*Ts]
type Alias[**P] = Callable[P]
2 changes: 2 additions & 0 deletions tests/functional/u/used/used_before_assignment_py312.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[testoptions]
min_pyver=3.12
Loading