ericvsmith / dataclasses

Apache License 2.0
587 stars 53 forks source link

Should isdataclass return True for both classes and instances? #99

Closed ericvsmith closed 6 years ago

ericvsmith commented 6 years ago

Raised by Carl Meyer in https://mail.python.org/pipermail/python-dev/2017-November/150850.html.

I think he's probably correct. The current behavior, where it only works on instances, is surprising. The equivalent attrs API, attr.has(), returns True for both classes and instances.

gvanrossum commented 6 years ago

I'm not keen on perpetuation confusion between classes and instances -- it makes code harder to read. E.g. when I see

def foo(a):
    assert isdataclass(a)

I can't tell whether a is supposed to be a class or an instance.

ilevkivskyi commented 6 years ago

Also note that if we are going to change this, then asdict and astuple should be updated, since they use isdataclass to work only on instances.

ericvsmith commented 6 years ago

I've already verified that there's an existing test that fails if isdataclass is changed.

ericvsmith commented 6 years ago

I think I'm just going to delete isdataclass, since I can't come up with a good use case for it. It's easy enough to add later.

ericvsmith commented 6 years ago

I've added on how to implement isdataclass() to the PEP.