-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Multiple inheritance triggers issues that cannot be resolved #4335
Comments
Please start by changing the type of all your |
Running on 0.560 and fixing the
It appears mypy is passing all of the arguments to |
It's not specific to classes; the super call arguments are just passed to the first base class (which statically is the best thing to do, though not sound). The first two errors are because object() doesn't take arguments. The latter seems a bug that I can repro like this: def f(foo: str, bar: str) -> None:
pass
def g() -> None:
args: tuple
f(foo='', *args) # E: "f" gets multiple values for keyword argument "foo" I think I've seen this before; there's something wrong with the way |
@gvanrossum Yes, I also have seen this. I think this may be a bug in |
@gvanrossum's repro gives the same error on This is my test.py:
In fact, it's just the usual error from following a keyword arg with a positional arg. As Similarly, the error above is indicating that passing a fourth argument to the As such I don't think there's a real issue here. |
Ah, yes. That example gives a similar error when executed:
|
But the original code fails in mypy while it works at runtime. Here is the repro with obvious errors fixed: class BaseClass(object):
def __init__(self, foo: str, *args: Any, **kwargs: Any) -> None:
self.foo = foo
super().__init__(*args, **kwargs) # E: Too many arguments for "__init__" of "object"
class Mixin(object):
def __init__(self, bar: str, baz: Optional[str] = None, *args: Any, **kwargs: Any) -> None:
self.bar = bar
self.baz = baz or 'baz2'
super().__init__(*args, **kwargs) # E: Too many arguments for "__init__" of "object"
class Derived(BaseClass, Mixin):
def __init__(self, foo: str, bar: str, other: str, *args: Any, **kwargs: Any) -> None:
self.other = other
super().__init__(foo=foo, bar=bar, *args, **kwargs) # E: "__init__" of "BaseClass" gets multiple values for keyword argument "foo"
d = Derived('foo', 'bar', 'other') |
Any workaround we can use while waiting for a fix? |
I think |
When using multiple inheritance, the mixing of arguments to different base classes triggers warnings that cannot be resolved.
The text was updated successfully, but these errors were encountered: