Skip to content

Commit

Permalink
Fix used-before-assignment FP for generic type syntax (Py 3.12) (#9150
Browse files Browse the repository at this point in the history
)

* Fix `used-before-assignment` FP for generic type syntax (Py 3.12)

* Bump astroid to 3.0.1

(cherry picked from commit cb29fbd)
  • Loading branch information
jacobtylerwalls authored and github-actions[bot] committed Oct 16, 2023
1 parent a9d9dc3 commit 068f8fc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
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

0 comments on commit 068f8fc

Please sign in to comment.