Best way to access name mangled names in Python outside the class -
i use name mangled name in python, avoid subclasses accessing attribute. know can _classname__attributename
, according http://docs.python.org/2/reference/expressions.html#atom-identifiers, "if transformed name extremely long (longer 255 characters), implementation defined truncation may happen. if class name consists of underscores, no transformation done." i'm particularly worried "implementation defined" part. seems there subtleties. there standard library function convert class name plus attribute name name mangled equivalent?
background
i want decorate class's docstring able whether or not requires optional external dependencies, can automatically enabled or disabled in doctest runner (full details @ https://github.com/sympy/sympy/pull/1969).
ideally, this, add attribute docstring, python not allow adding attributes strings. instead, have add attribute class. need attribute not inherited subclasses, since docstrings not inherited. otherwise, subclasses have docstrings incorrectly decorated. original solution use descriptor object disables attribute subclasses, little complicated when name mangling exists this, excepting 1 subtlety.
Comments
Post a Comment