Commit b1adce4a authored by Stefan Behnel's avatar Stefan Behnel

when mangling private attributes in Python classes, leading underscores must...

when mangling private attributes in Python classes, leading underscores must be removed from the class name before mangling
parent bce8b981
......@@ -1636,7 +1636,7 @@ class PyClassScope(ClassScope):
def mangle_special_name(self, name):
if name and name.startswith('__') and not name.endswith('__'):
name = EncodedString('_%s%s' % (self.class_name, name))
name = EncodedString('_%s%s' % (self.class_name.lstrip('_'), name))
return name
def lookup_here(self, name):
......
......@@ -76,3 +76,20 @@ class CyTestSub(CyTest):
def get(o):
return o._CyTest__x, o._CyTestSub__y, o.__y, o.__private()
return get(self)
class _UnderscoreTest(object):
"""
>>> ut = _UnderscoreTest()
>>> '__x' in dir(ut)
False
>>> '_UnderscoreTest__x' in dir(ut)
True
>>> ut._UnderscoreTest__x
1
>>> ut.get()
1
"""
__x = 1
def get(self):
return self.__x
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment