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
Async callable which accepts a parameter with a union type, returns a union type and has @overload on said parameter has its return type erased when awaited. I'm hoping this sentence makes any sense, but in any case (pun not intended) the code snippet should demonstrate the issue.
To Reproduce
Here's the absolute minimum reproduction I could muster:
fromtypingimportoverloadclassA: passclassB: pass@overloadasyncdeffoo(x: A) ->B: ...
@overloadasyncdeffoo(x: B) ->A: ...
asyncdeffoo(x: A|B) ->A|B:
returnA() ifisinstance(x, B) elseB()
asyncdefbreaks(x: A|B) ->None:
y=awaitfoo(x)
reveal_type(y) # Reveals Any, should reveal A | B
The following includes non async version of this code which actually works.
await foo(x) in the above example should have type A | B.
Actual Behavior
note: Revealed type is "Any" is the actual result.
Your Environment
Original bug was found on Python 3.10 and mypy 0.991, with --strict and a number of per-file settings. I can include relevant excerpt of our pyproject.toml, although it seems that this issue is not configuration-specific.
On the playground the following was tried:
Mypy version used: 0.991 (also tried with latest master as well as a random sampling of versions between 0.670 and 0.990
Mypy command-line flags: none and --strict, in fact none of the flag combinations lead to correct result
Python version used: 3.10, 3.11
The text was updated successfully, but these errors were encountered:
Bug Report
Async callable which accepts a parameter with a union type, returns a union type and has
@overload
on said parameter has its return type erased when awaited. I'm hoping this sentence makes any sense, but in any case (pun not intended) the code snippet should demonstrate the issue.To Reproduce
Here's the absolute minimum reproduction I could muster:
The following includes non async version of this code which actually works.
Gist URL: https://gist.github.com/2f8288673587ff27f6fca5024ddd0543
Playground URL: https://mypy-play.net/?mypy=master&python=3.11&gist=2f8288673587ff27f6fca5024ddd0543&flags=strict
Expected Behavior
await foo(x)
in the above example should have typeA | B
.Actual Behavior
note: Revealed type is "Any"
is the actual result.Your Environment
Original bug was found on Python 3.10 and mypy 0.991, with
--strict
and a number of per-file settings. I can include relevant excerpt of ourpyproject.toml
, although it seems that this issue is not configuration-specific.On the playground the following was tried:
master
as well as a random sampling of versions between0.670
and0.990
--strict
, in fact none of the flag combinations lead to correct resultThe text was updated successfully, but these errors were encountered: