Skip to content

Commit 759e2cc

Browse files
Fix used-before-assignment FP for generic type syntax (Py 3.12) (#9150) (#9154)
* Fix `used-before-assignment` FP for generic type syntax (Py 3.12) * Bump astroid to 3.0.1 (cherry picked from commit cb29fbd) Co-authored-by: Jacob Walls <[email protected]>
1 parent a77f0c1 commit 759e2cc

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix ``used-before-assignment`` false positive for generic type syntax (PEP 695, Python 3.12).
2+
3+
Closes #9110

pylint/checkers/variables.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
nodes.Expr,
121121
nodes.Return,
122122
nodes.Match,
123+
nodes.TypeAlias,
123124
)
124125

125126

@@ -2329,6 +2330,8 @@ def _maybe_used_and_assigned_at_once(defstmt: nodes.Statement) -> bool:
23292330
return any(case.guard for case in defstmt.cases)
23302331
if isinstance(defstmt, nodes.IfExp):
23312332
return True
2333+
if isinstance(defstmt, nodes.TypeAlias):
2334+
return True
23322335
if isinstance(defstmt.value, nodes.BaseContainer):
23332336
return any(
23342337
VariablesChecker._maybe_used_and_assigned_at_once(elt)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies = [
4141
# Also upgrade requirements_test_min.txt.
4242
# Pinned to dev of second minor update to allow editable installs and fix primer issues,
4343
# see https://github.com/pylint-dev/astroid/issues/1341
44-
"astroid>=3.0.0,<=3.1.0-dev0",
44+
"astroid>=3.0.1,<=3.1.0-dev0",
4545
"isort>=4.2.5,<6",
4646
"mccabe>=0.6,<0.8",
4747
"tomli>=1.1.0;python_version<'3.11'",

requirements_test_min.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.[testutils,spelling]
22
# astroid dependency is also defined in pyproject.toml
3-
astroid==3.0.0 # Pinned to a specific version for tests
3+
astroid==3.0.1 # Pinned to a specific version for tests
44
typing-extensions~=4.8
55
py~=1.11.0
66
pytest~=7.4
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""used-before-assignment re: python 3.12 generic typing syntax (PEP 695)"""
2+
3+
from typing import Callable
4+
type Point[T] = tuple[T, ...]
5+
type Alias[*Ts] = tuple[*Ts]
6+
type Alias[**P] = Callable[P]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[testoptions]
2+
min_pyver=3.12

0 commit comments

Comments
 (0)