pylint
pylint copied to clipboard
Unexpected behavior when dealing with Protocol generics
Bug description
Minimal Repro, see inline comments for false positive descriptions
"""My module docstring."""
from collections.abc import Sized
from typing import Protocol, TypeVar
from typing_extensions import override, TypeAlias
# pylint: disable=too-few-public-methods
T = TypeVar("T")
V = TypeVar("V")
class MyClass(Sized, Protocol[T, V]):
"""My class docstring."""
def my_method(self):
"""My docstring."""
... # unnecessary-ellipse, but this is used as implementation "placeholder"
# unsubscriptable-object, but inherits from Generic Protocol
class MySubclass(MyClass[T, V]):
"""My class docstring."""
def __len__(self) -> int:
return 0
@override
def my_method(self): # missing-function-docstring, but overrides MyClass
return
# --------------------------------------------------------------------------- #
class AnotherClass(Protocol[T, V]):
"""My class docstring."""
MyAlias: TypeAlias = AnotherClass[T, int]
foobar = MyAlias[
bool
] # unsubscriptable-object, but just aliased the generic type variable above
Configuration
No response
Command used
pylint
Pylint output
************* Module pylint_bugs
sandbox/pylint_bugs.py:18:8: W2301: Unnecessary ellipsis constant (unnecessary-ellipsis)
sandbox/pylint_bugs.py:22:17: E1136: Value 'MyClass' is unsubscriptable (unsubscriptable-object)
sandbox/pylint_bugs.py:29:4: C0116: Missing function or method docstring (missing-function-docstring)
sandbox/pylint_bugs.py:40:9: E1136: Value 'MyAlias' is unsubscriptable (unsubscriptable-object)
Expected behavior
No errors
Pylint version
pylint 3.2.6
astroid 3.2.4
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
OS / Environment
No response
Additional dependencies
No response