[Python-ideas] PEP 526: why ClassVar instead of ClassAttr?
Steven D'Aprano
steve at pearwood.info
Tue May 16 19:23:38 EDT 2017
Since PEP 526 is already provisionally accepted, it may be too late to
bring this up, but I have a question and suggestion about the name
ClassVar. I've read the PEP but didn't see an answer or rejection to
this.
https://www.python.org/dev/peps/pep-0526/
Why choose ClassVar over ClassAttr when the usual terminology used in
the Python community is class and instance *attributes* rather than
"variables"?
I understand that, in a sense, attributes are variables (unless they're
constants *wink*) but the term "class variable" sounds very Java-esque
rather than Pythonic. And it is an uncomfortable fit with a language
like Python where classes are first class values like ints, strings,
floats etc:
- we talk about a string variable meaning a variable holding a string;
- a float variable is a variable holding a float;
- a list variable is a variable holding a list;
- so a class variable ought to be a variable holding a class.
I get the intention: we have local, global, instance and class
variables. But I feel that grouping instance/class with local/global is
too abstract and "computer sciencey": in practice, instance/class vars
are used in ways which are different enough from global/local vars that
they deserve a different name: attributes, members or properties are
common choices.
(Python of course uses attributes, and properties for a particular kind
of computed attribute.)
This introduces split terminology: we now talk about annotating class
attributes with ClassVar. Since there's no GlobalVar, NonLocalVar or
LocalVar, there doesn't seem to be any good reason to stick with the
FooVar naming system.
Can we change the annotation to ClassAttr instead?
--
Steve
More information about the Python-ideas
mailing list