Skip to content

Commit 9a9db8f

Browse files
Update astroid to 3.2.2 (#9655) (#9656)
* Update astroid to 3.2.2 * Add tests for generic class syntax (cherry picked from commit 032ab32) Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
1 parent 9223172 commit 9a9db8f

7 files changed

+80
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix multiple false positives for generic class syntax added in Python 3.12 (PEP 695).
2+
3+
Closes #9406

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.2.1,<=3.3.0-dev0",
44+
"astroid>=3.2.2,<=3.3.0-dev0",
4545
"isort>=4.2.5,<6,!=5.13.0",
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.2.1 # Pinned to a specific version for tests
3+
astroid==3.2.2 # Pinned to a specific version for tests
44
typing-extensions~=4.11
55
py~=1.11.0
66
pytest~=7.4
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# pylint: disable=missing-docstring,too-few-public-methods
2+
from typing import Generic, TypeVar, Optional
3+
4+
_T = TypeVar("_T")
5+
6+
7+
class Entity(Generic[_T]):
8+
last_update: Optional[int] = None
9+
10+
def __init__(self, data: _T) -> None:
11+
self.data = data
12+
13+
14+
class Sensor(Entity[int]):
15+
def __init__(self, data: int) -> None:
16+
super().__init__(data)
17+
18+
def async_update(self) -> None:
19+
self.data = 2
20+
21+
if self.last_update is None:
22+
pass
23+
self.last_update = 2
24+
25+
26+
class Switch(Entity[int]):
27+
def __init__(self, data: int) -> None:
28+
Entity.__init__(self, data)
29+
30+
31+
class Parent(Generic[_T]):
32+
def __init__(self):
33+
self.update_interval = 0
34+
35+
36+
class Child(Parent[_T]):
37+
def func(self):
38+
self.update_interval = None
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# pylint: disable=missing-docstring,too-few-public-methods
2+
class Entity[_T: float]:
3+
last_update: int | None = None
4+
5+
def __init__(self, data: _T) -> None: # [undefined-variable] # false-positive
6+
self.data = data
7+
8+
9+
class Sensor(Entity[int]):
10+
def __init__(self, data: int) -> None:
11+
super().__init__(data)
12+
13+
def async_update(self) -> None:
14+
self.data = 2
15+
16+
if self.last_update is None:
17+
pass
18+
self.last_update = 2
19+
20+
21+
class Switch(Entity[int]):
22+
def __init__(self, data: int) -> None:
23+
Entity.__init__(self, data)
24+
25+
26+
class Parent[_T]:
27+
def __init__(self):
28+
self.update_interval = 0
29+
30+
31+
class Child[_T](Parent[_T]): # [undefined-variable] # false-positive
32+
def func(self):
33+
self.update_interval = None
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
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
undefined-variable:5:29:5:31:Entity.__init__:Undefined variable '_T':UNDEFINED
2+
undefined-variable:31:23:31:25:Child:Undefined variable '_T':UNDEFINED

0 commit comments

Comments
 (0)