Closed
Description
Feature
In cpython
>>> class A:
... def __init__(self):
... self.__a = 1
...
>>> a = A()
>>> a.__a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute '__a'
>>> a._A__a
1
In Rustpython
>>>>> class A:
..... def __init__(self):
..... self.__a = 1
.....
>>>>> a = A()
>>>>> a.__a
1
In python, the field of the class starting with __
is a private field,
and mangling is performed to prevent external access to the same variable.
Currently, this has not been done in Rustpython
.
Python Documentation
https://github.com/python/cpython/blob/3185267400be853404f22a1e06bb9fe1210735c7/Python/compile.c#L254-L256
In cpython, it is probably mangled using the above function.