support dunder variables #122

Open
opened 2021-12-02 10:49:28 +08:00 by sb10q · 2 comments
Owner

(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.
Contributor

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.
Siddhangana was assigned by sb10q 2024-12-11 11:34:04 +08:00
Siddhangana added reference feature/support-dunder 2024-12-17 10:33:31 +08:00
Siddhangana removed reference feature/support-dunder 2024-12-17 11:18:59 +08:00
Collaborator

May I ask for nac3artiq/src/codegen.rs. what info does the name field hold in this context? My intention is to access Python class name for the given symbol (after the symbol name querying when it's dunder)
And whether it could be as simple as accessing self.name for ArtiqCodeGenerator struct or it is best to be done dynamically from Python (by using timeline?) or even if it requires AST traversal

image

May I ask for nac3artiq/src/codegen.rs. what info does the name field hold in this context? My intention is to access Python class name for the given symbol (after the symbol name querying when it's dunder) And whether it could be as simple as accessing self.name for ArtiqCodeGenerator struct or it is best to be done dynamically from Python (by using timeline?) or even if it requires AST traversal ![image](/attachments/c015364c-e992-44cd-ac73-ff67cedab1fb)
162 KiB
Sign in to join this conversation.
No Milestone
No Assignees
3 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
No description provided.