class-private names and the Zen of Python

Marco Buttu marco.buttu at gmail.com
Tue Oct 8 06:13:48 EDT 2013


In the following case:

 >>> class Foo:
...     _Foo__a = 100
...     __a = 33
...
 >>> Foo._Foo__a
33

I think this behavior, for a user who does not know the convention, 
could be a surprise. Should be raising an exception (in order to inform 
the user the transformation of the name __a have been replaced an 
existing name) a possible --explicit-- alternative?

Another question is: where is the place in which this transformation 
occurs? Is it at the parser level, before the dictionary attribute is 
gave as argument to the metaclass?

I looked at the documentation:

http://docs.python.org/3/reference/lexical_analysis.html
http://docs.python.org/3/reference/expressions.html#atom-identifiers

but it is not clear when this transformation happens.

-- 
Marco Buttu



More information about the Python-list mailing list