-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive non-parent-init-called with base inheriting Generic and Protocol #3505
Comments
Thanks for the report. It seems |
I have a proof of concept that fixes this and also #3131, by having Edit: Something fishy is going on: what makes the test case pass is a side effect of calling |
I am just hitting this false positive as well, nice work @mthuurne . I would like to add that inheriting from Please see the below sample code: from typing import Generic, TypeVar
T = TypeVar("T") # pylint: disable=invalid-name
class Base:
pass
class Mixin(Generic[T]):
pass
class Child1(Base, Mixin[float]):
def __init__(self):
Base.__init__(self)
Mixin.__init__(self) # Raises W0233 (non-parent-init-called)
class Child2(Base, Mixin[float]):
def __init__(self):
super().__init__()
super(Child2, self).__init__() # Doesn't raise W0233
class Child3(Mixin[float]):
def __init__(self):
Mixin.__init__(self) # Raises W0233 (non-parent-init-called) And the pylint output:
Versions
|
This seems to be fixed with |
As far as my |
@cdce8p Not yet from typing import Any, Protocol, runtime_checkable, TypeVar
T = TypeVar("T")
T_co = TypeVar("T_co", covariant=True)
@runtime_checkable
class ROProperty(Protocol[T_co]):
def __get__(self, instance: Any, owner: Any = None) -> T_co | None:
...
@runtime_checkable
class RWProperty(ROProperty[T], Protocol):
def __set__(self, instance: Any, value: T):
...
class NamedPropMixin:
...
class KWProp(NamedPropMixin, RWProperty[T]): # E0239: Inheriting 'RWProperty[T]', which is not a class. (inherit-non-class)
... |
Could you check again? I just tried reproducing it with the current |
I'm still seeing this. See this code: class ParentA[I: int]():
def __init__(self) -> None:
# imagine more stuff was done here
pass
class Child1[I: int](ParentA[I]):
def __init__(self, arg: I) -> None:
ParentA.__init__(self)
self._arg = arg
class Child2[I: int](ParentA[I]):
def __init__(self) -> None:
ParentA[I].__init__(self) Child1 generates a lint in its {
"type": "warning",
"module": "test",
"obj": "Child1.__init__",
"line": 8,
"column": 8,
"endLine": 8,
"endColumn": 24,
"path": "test.py",
"symbol": "non-parent-init-called",
"message": "__init__ method from a non direct base class 'ParentA' is called",
"message-id": "W0233"
} This can be resolved (w.r.t. pylint) with the syntax in
I'm using the VSCode extension, which specifies:
|
@mheripsos Unfortunately this is quite an old version. Please try the latest release |
Excellent, that immediately resolved it. I was still studying this and seeing some truly bizarre behavior I was going to follow up with, but it seems like you guys have got it figured out with the new versions. Thanks. |
Steps to reproduce
Run PyLint on:
Note that
typing.Protocol
is new in Python 3.8. In older Python versions you can get it from thetyping_extensions
package.Current behavior
Expected behavior
No warning is issued.
pylint --version output
Workaround
Using
super
instead of explicitly calling the base class__init__
avoids the warning.The text was updated successfully, but these errors were encountered: