-
-
Notifications
You must be signed in to change notification settings - Fork 3k
TypedDict with generic function #9827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
achimnol
added a commit
to lablup/backend.ai-manager
that referenced
this issue
Dec 20, 2020
This is still happening with v0.800 release.
|
For what it's worth I have a minimal example here: from typing import TypedDict, TypeVar, Type, cast
class Alpha(TypedDict):
pass
class Beta:
pass
_T = TypeVar("_T")
def foo(td: Type[_T]) -> _T:
pass
def baz_alpha() -> Alpha:
return foo(Alpha) # Incompatible return value type (got "Alpha", expected "Alpha")
def baz_alpha_cast() -> Alpha:
return cast(Alpha, foo(Alpha)) # no error, no warning about a redundant cast
def baz_beta() -> Beta:
return foo(Beta) # no error
def baz_int() -> int:
return foo(int) # no error Python 3.9.1 and mypy 0.800. Incidentally, I am also unable to use |
I think this bug has been fixed. I'm not able to repro it with the latest version of mypy. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
Using a TypedDict with a generic function gives a strange type error with the same "expected" and "actual" types.
I also wonder that if we could use
TypeVar('TD', bound=TypedDict)
as well.(NOTE: This is a follow-up to #9820)
To Reproduce
Given
and
,
running mypy against the following code snippet
reports
Expected Behavior
It should pass the type check, or give a more understandable error message.
Actual Behavior
It's reporting a type error with the same "expected" and "actual" types.
Your Environment
python -m mypy src/ai/backend tests
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: