You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incompatible override when overriding non-overload with overload #12379
But as far as I can see this is safe. Mypy accepts a union as an argument to B.f:
arg: Union[int, str]
B().f(arg)
Of course, the overloads are useless in this toy example, but the error also comes up if you vary the return type in the overloads. This came up in python/typeshed#7510.
This can also go the other way around - something I encountered while working with Tkinter and subclassing widgets:
from __future__ importannotationsfromtypingimportAny, overload# defined within the tkinter itself (roughly)classBaseWidget:
@overloaddefconfigure(self, arg: int) ->int:
...
@overloaddefconfigure(self, arg: str) ->str:
...
defconfigure(self, arg: int|str) ->int|str:
...
config=configure# alias for the 'configure' method# my subclassclassSubWidget(BaseWidget):
# overwrite 'configure' with a pass-through function that runs some extra code first# NOTE: 'Any' usage to not have to replicate the overloads, this type-checks just finedefconfigure(self, *args: Any, **kwargs: Any) ->Any:
... # some extra codesuper().configure(*args, **kwargs)
# ..., but the alias complainsconfig=configure# error: Incompatible types in assignment (expression has type "Callable[[SubWidget, VarArg(Any), KwArg(Any)], Any]", base class "BaseWidget" defined the type as overloaded function)
Activity
JelleZijlstra commentedon Mar 19, 2022
Possibly a duplicate of #495
DevilXD commentedon Mar 26, 2022
This can also go the other way around - something I encountered while working with Tkinter and subclassing widgets:
Current workaround:
Handle edge case in overload subtyping (python#22007)