ericvsmith / dataclasses

Apache License 2.0
587 stars 53 forks source link

PEP 8 function names: asdict -> as_dict, astuple -> as_tuple #110

Closed ericvsmith closed 6 years ago

ilevkivskyi commented 6 years ago

I don't think this improves readability. I would even say that using underscores in such short names looks a bit weird.

warsaw commented 6 years ago

Actually, I agree with @ericvsmith that underscores improve readability, so I'm +1 on as_dict and as_tuple. There are a lot of places in the stdlib that use wordswithoutunderscores (e.g. isinstance) so consistency is more important, but for new APIs, we should use underscore names.

gvanrossum commented 6 years ago

Otoh this is similar to namedtuple._asdict.

hynek commented 6 years ago

FWIW, I’m a huge fan of underscores and their lack bothers me in asdict. But as Guido points out, we have a precedent and I found it unfortunate/confusing to build an API that has the same name but a different spelling.

ericvsmith commented 6 years ago

Okay, let's leave this as-is, without the underscore. I'll add a note to the PEP that we're choosing consistency with existing APIs as the reason.

ericvsmith commented 6 years ago

PEP updated.

alexmojaki commented 6 years ago

Would it be bad to have an alias as_dict = asdict? I see this is something that is not generally done in the standard library but I don't know why.

This is not meant to imply that I am bothered by the name asdict, I'm just wondering why not both.

ericvsmith commented 6 years ago

We wouldn't want to have two names for the same thing. It adds confusion.