support dunder variables #122

Open
opened 2021-12-02 10:49:28 +08:00 by sb10q · 1 comment

(From M-Labs/nac3-spec#26)
Currently, dunder variables and methods (e.g. self.__variable) cannot be used in kernels as the compiler cannot find the attributes. I am not really sure how complex it would be to support that, but it could be a nice-to-have. Right now we sometimes need to make long variable/method names for base classes to make sure there is no name aliasing in sub-classes.

(From https://git.m-labs.hk/M-Labs/nac3-spec/issues/26) Currently, dunder variables and methods (e.g. `self.__variable`) cannot be used in kernels as the compiler cannot find the attributes. I am not really sure how complex it would be to support that, but it could be a nice-to-have. Right now we sometimes need to make long variable/method names for base classes to make sure there is no name aliasing in sub-classes.

https://docs.python.org/3/tutorial/classes.html#tut-private

Any identifier of the form __spam (at least two leading underscores, at most one trailing underscore) is textually replaced with _classname__spam, where classname is the current class name with leading underscore(s) stripped.

>>> class A:
...     def __init__(self):
...         self.__a = 1
... 
>>> a = A()
>>> a.__dict__
{'_A__a': 1}

Probably not too hard I guess.

https://docs.python.org/3/tutorial/classes.html#tut-private > Any identifier of the form `__spam` (at least two leading underscores, at most one trailing underscore) is textually replaced with `_classname__spam`, where `classname` is the current class name with leading underscore(s) stripped. ```python >>> class A: ... def __init__(self): ... self.__a = 1 ... >>> a = A() >>> a.__dict__ {'_A__a': 1} ``` Probably not too hard I guess.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#122
There is no content yet.