Код: Выделить всё
import typing
class Base:
def fun(self, a: str):
pass
SomeType = typing.NewType('SomeType', str)
class Derived(Base):
def fun(self, a: SomeType):
pass
Код: Выделить всё
mypy mypy_test.py
mypy_test.py:10: error: Argument 1 of "fun" incompatible with supertype "Base"
Версии программного обеспечения:
mypy 0.650
Python 3.7.1
Что я пробовал:
Код: Выделить всё
import typing
class Base:
def fun(self, a: typing.Type[str]):
pass
SomeType = typing.NewType('SomeType', str)
class Derived(Base):
def fun(self, a: SomeType):
pass
Один пользователь прокомментировал: «Похоже, вы не можете сузить допустимые типы в переопределенном методе?»
Но в этом случае, если я использую максимально широкий тип (
Код: Выделить всё
typing.Any
Код: Выделить всё
import typing
class Base:
def fun(self, a: typing.Any):
pass
SomeType = typing.NewType('SomeType', str)
class Derived(Base):
def fun(self, a: SomeType):
pass
Подробнее здесь: https://stackoverflow.com/questions/543 ... -supertype