Skip to content

Commit

Permalink
Update astroid to 3.2.2 (#9655) (#9656)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
github-actions[bot] and cdce8p committed May 20, 2024
1 parent 9223172 commit 9a9db8f
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9406.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix multiple false positives for generic class syntax added in Python 3.12 (PEP 695).

Closes #9406
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.2.1,<=3.3.0-dev0",
"astroid>=3.2.2,<=3.3.0-dev0",
"isort>=4.2.5,<6,!=5.13.0",
"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.2.1 # Pinned to a specific version for tests
astroid==3.2.2 # Pinned to a specific version for tests
typing-extensions~=4.11
py~=1.11.0
pytest~=7.4
Expand Down
38 changes: 38 additions & 0 deletions tests/functional/g/generic_class_syntax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# pylint: disable=missing-docstring,too-few-public-methods
from typing import Generic, TypeVar, Optional

_T = TypeVar("_T")


class Entity(Generic[_T]):
last_update: Optional[int] = None

def __init__(self, data: _T) -> None:
self.data = data


class Sensor(Entity[int]):
def __init__(self, data: int) -> None:
super().__init__(data)

def async_update(self) -> None:
self.data = 2

if self.last_update is None:
pass
self.last_update = 2


class Switch(Entity[int]):
def __init__(self, data: int) -> None:
Entity.__init__(self, data)


class Parent(Generic[_T]):
def __init__(self):
self.update_interval = 0


class Child(Parent[_T]):
def func(self):
self.update_interval = None
33 changes: 33 additions & 0 deletions tests/functional/g/generic_class_syntax_py312.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# pylint: disable=missing-docstring,too-few-public-methods
class Entity[_T: float]:
last_update: int | None = None

def __init__(self, data: _T) -> None: # [undefined-variable] # false-positive
self.data = data


class Sensor(Entity[int]):
def __init__(self, data: int) -> None:
super().__init__(data)

def async_update(self) -> None:
self.data = 2

if self.last_update is None:
pass
self.last_update = 2


class Switch(Entity[int]):
def __init__(self, data: int) -> None:
Entity.__init__(self, data)


class Parent[_T]:
def __init__(self):
self.update_interval = 0


class Child[_T](Parent[_T]): # [undefined-variable] # false-positive
def func(self):
self.update_interval = None
2 changes: 2 additions & 0 deletions tests/functional/g/generic_class_syntax_py312.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[testoptions]
min_pyver=3.12
2 changes: 2 additions & 0 deletions tests/functional/g/generic_class_syntax_py312.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
undefined-variable:5:29:5:31:Entity.__init__:Undefined variable '_T':UNDEFINED
undefined-variable:31:23:31:25:Child:Undefined variable '_T':UNDEFINED

0 comments on commit 9a9db8f

Please sign in to comment.