Skip to content

Instantly share code, notes, and snippets.

@elliott-beach
Last active December 30, 2017 03:33
Show Gist options
  • Save elliott-beach/eee64bba55ab734eac4b5cd5631b8ead to your computer and use it in GitHub Desktop.
Save elliott-beach/eee64bba55ab734eac4b5cd5631b8ead to your computer and use it in GitHub Desktop.
How to resolve the error for mypy #4335
from typing import Any, Dict, Optional, Sequence, Tuple
class BaseClass(object):
def __init__(self, foo: str, *args: Any, **kwargs: Any) -> None:
self.foo = foo
super().__init__(*args, **kwargs)
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)
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, **kwargs) # Don't pass *args here, it would cause an error if there was a 4th positional argument.
d = Derived('foo', 'bar', 'other')
print(d.foo)
print(d.bar)
print(d.other)
print(d.baz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment