-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
is_dataclass
returns True
if getattr
always succeeds.
#82049
Comments
Given a class
An instance of this class is always identified as a dataclass.
gives the output Possible fix: check for the instance type.
does give the correct answer. |
I'm guessing I'm looking up the attribute on the instance, not the class. |
I am not sure that it is good idea to accept a type and an instance, but if it is a goal, is_dataclass() should be defined as: def is_dataclass(obj):
cls = obj if isinstance(obj, type) else type(obj)
return hasattr(cls, _FIELDS) _is_dataclass_instance() should be changed too: def _is_dataclass_instance(obj):
return hasattr(type(obj), _FIELDS) |
Yeah, I agree it's not an awesome design to work with classes or instances, but it's documented that way. As soon as I write some tests I'll check this in. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: