[issue37868] `is_dataclass` returns `True` if `getattr` always succeeds.

Serhiy Storchaka report at bugs.python.org
Thu Aug 15 16:04:31 EDT 2019


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

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)

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37868>
_______________________________________


More information about the Python-bugs-list mailing list