-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
bug: A class that derives from a dataclass should be labelled a dataclass #239
Comments
Hmmm, this one is problematic. Consider the following example: from dataclasses import dataclass
@dataclass
class A:
a: int
class B(A):
b: int
@dataclass
class C(B):
c: int
print(inspect.signature(A))
print(inspect.signature(B))
print(inspect.signature(C)) Running it will print:
It means that, to build the If we want to support this, I suppose we will have to use something else than the def is_dataclass(obj):
"""Returns True if obj is a dataclass or an instance of a
dataclass."""
cls = obj if isinstance(obj, type) else type(obj)
return hasattr(cls, _FIELDS) I find this confusing IMO, because in the above example, Any other idea? EDIT: Well I guess we can check the decorators everytime instead of the labels. Dynamic transformations at import time are not fun for static analysis... I like dataclasses less now, they're a can of worms in this context 😂 |
Yes checking the decorators. I did not know about it. Thanks for that one, I will change my "is_dataclass" checks to use that. |
Here is a failing test.
For reference, the parallel test in core python is.
The text was updated successfully, but these errors were encountered: