Bug description
Pylint reports E0602: Undefined variable 'uniqdict' when a method in a PEP 695 generic class uses the enclosing class in its return annotation.
"https://github.com/pylint-dev/pylint/issues/11211"
class uniqdict[K, V](dict[K, V]):
def __ior__(self, other, /) -> uniqdict[K, V]:
return self
Command used
pylint --rcfile=/dev/null --disable=all --enable=undefined-variable --py-version=3.12 pylint.py
Pylint output
pylint.py:3:35: E0602: Undefined variable 'uniqdict' (undefined-variable)
Expected behavior
no diagnostics
Pylint version
pylint 4.0.6
astroid 4.1.2
Python 3.14.6
OS / Environment
MSYS_NT-10.0-26100
Larger real-world example
import collections.abc
class uniqdict[K, V](dict[K, V]):
"""A mapping whose existing keys cannot be assigned different values."""
def __setitem__(self, key: K, value: V) -> None:
try:
if (old := super().__getitem__(key)) != value:
raise ValueError(self.__class__.__name__, key, old, value)
except KeyError:
super().__setitem__(key, value)
update = collections.abc.MutableMapping.update
def __ior__(self, other, /) -> uniqdict[K, V]:
self.update(other)
return self
Bug description
Pylint reports
E0602: Undefined variable 'uniqdict'when a method in a PEP 695 generic class uses the enclosing class in its return annotation.Command used
Pylint output
Expected behavior
no diagnostics
Pylint version
OS / Environment
MSYS_NT-10.0-26100
Larger real-world example