-
Notifications
You must be signed in to change notification settings - Fork 31
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
TypedDict is treated as different class as Dict[str, Any] #96
Comments
Hmm this is an interesting corner case. I will look into it later, but FWIW the workaround has nothing to do with dataclasses. Simply add that parameter to @OVERRIDES when you decorate a method to disable type-checking. class B(A):
@overrides(check_signature=False)
def func(self) -> MyTypedDict:
pass |
Thank you to look into :) |
As TypedDict is such an odd type, this requires somewhat more work. class A(TypedDict):
x: string
y: int
class B(TypedDict):
z: float
class C(A, B):
pass
A is Dict[str, Any]
B is Dict[str, Any] also Dict[str, float]
A and B are not compatible.
C is A, C is B. |
# From TypedDict source :/
def __subclasscheck__(cls, other):
# Typed dicts are only for static structural subtyping.
raise TypeError('TypedDict does not support instance and class checks') |
TypedDict is now treated like |
Hi
Thank you for doing this great library!
Current behavior
Currently, I'm facing a strange behavior. I want to annotate a return type of certain method with a TypedDict when it's parent is typed as Dict[str, Any]. However,
overrides
complains that the return type isn't compatible.See the example:
The error is
TypeError: B.func: return type `<class '__main__.MyTypedDict'>` is not a `typing.Dict[str, typing.Any]
.Looking at the code, the error may come from typing_utils.issubtype.
Ideally
From my understanding, it should work as
MyTypedDict
is a valid return type fortyping.Dict[str, typing.Any]
.Workaround
Set
check_signature
to False ->@overrides(check_signature=False)
Sadly, I can't use dataclasses as the library that I'm using doesn't support them.
The text was updated successfully, but these errors were encountered: