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
The order of declarations shouldn't matter to mypy w.r.t.1 type annotations when from __future__ import annotations is in effect, but in the example that follows, they do.
To Reproduce
Analyze the following code with --strict (or run on mypy-play.net):
from __future__ importannotationsimportfunctoolsfromtypingimport (
Any,
Callable,
cast,
Counter,
Optional,
TypeVar,
)
Tc=TypeVar('Tc', bound=Callable[..., Any])
deffunc_wraps(wraps: Tc) ->Callable[[Callable[..., Any]], Tc]:
'''declare that one function wraps another Args: wraps: the function being wrapped Returns: a function 'decorator()', where... Args: the function which wraps 'wraps' Returns: the input argument, unchanged The type annotations of the return value of the 'decorator()' will be those of 'wraps'. '''definner(wrapper: Callable[..., Any], /) ->Tc:
'''decorator Args: wrapper: the function which wraps 'wraps' Returns: the same function, unchanged '''wrapper_=cast(Tc, wrapper)
returnfunctools.wraps(wraps)(wrapper_)
returninnerdeffunction1() ->ChildClass:
returnChildClass()
classParentClass:
def__init__(self, *, param: Optional[int] =None) ->None:
_=paramclassChildClass(ParentClass):
some_counter: Counter[int]
@func_wraps(ParentClass.__init__)def__init__(self, *args: Any, **kwargs: Any):
super().__init__(*args, **kwargs)
self.some_counter=Counter()
deffunction2() ->ChildClass:
returnChildClass()
This replaces #14509.
Bug Report
The order of declarations shouldn't matter to mypy w.r.t.1 type annotations when
from __future__ import annotations
is in effect, but in the example that follows, they do.To Reproduce
Analyze the following code with
--strict
(or run on mypy-play.net):Expected Behavior
There should be no errors.
Actual Behavior
The following error is issued w.r.t.1
function1
:Your Environment
--show-error-codes --strict --warn-unreachable
mypy.ini
(and other config files): N/AFootnotes
with respect to ↩ ↩2
The text was updated successfully, but these errors were encountered: