Python slang

Chris Angelico rosuav at gmail.com
Sat Aug 6 23:02:12 EDT 2016


On Sun, Aug 7, 2016 at 12:32 PM, Steven D'Aprano
<steve+python at pearwood.info> wrote:
> By "atomic type", I mean a class which "feels" like it is a primitive,
> low-level structure rather than an object with attributes, for example:
>
> - builtins int, float, str, bytes, dict, list, tuple, set, frozenset, bool;
> - array from the array module;
> - defaultdict and deque from collections;
>
> but not
>
> - Decimal from decimal module;
> - Fraction from fractions module;
> - Counter and ChainMap from collections module.
>
>
> although I suppose ChainMap does expose at least the "maps" attribute. But
> in my opinion Decimal, Fraction and Counter should all be lowercased, like
> float, int and dict.

I somewhat agree with you about Decimal and Fraction, but not Counter.
In that situation, I'd be more inclined to make DefaultDict than
counter, if consistency is needed; there are too many other ways the
word "counter" can be used, so I'd rather not dedicate it to a class.
IMO the only types that really deserve the lower-case name are
built-ins (or ones where they're really functions in disguise, like
functools.partial). Of course, there's no point renaming them now, but
I don't see any particular value in "a modified version of dict"
getting a lower-case name - if I subclass dict myself, PEP 8 says it
should be called MyDict, not mydict, and defaultdict should be no
different.

The only reason Decimal and Fraction could plausibly be lowercased is
that they function very much the same way that int and float do, and
also they could potentially become builtins. But they probably won't,
so I don't have any problem with them remaining as they are, feeling
like classes rather than feeling like atoms.

ChrisA



More information about the Python-list mailing list