Accessing class attributes within nested classes: AttributeError: 'getset_descriptor' object has no attribute '...' #4360
-
I am looking to port an existing Python data structure to Rust via PyO3. The original code uses nested classes, and class attributes, to represent a static and constant data structure:
Note that these classes are never instantiated, instead they are consumed by code as read-only constants, such as:
Essentially, classes are used only as namespaces. With PyO3 I seem to have run into an issue with
With this definition, the following works OK:
But attempting to access the inner class attribute via the full hierarchy fails:
Is there a way to implement this static hierarchy with PyO3? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
This puts a You need to use something like |
Beta Was this translation helpful? Give feedback.
-
I think you want something like:
|
Beta Was this translation helpful? Give feedback.
This puts a
Cpu
attribute on instances ofSystem
, it doesn't put it on theSystem
class itself.You need to use something like
classattr
to put an attribute on the class.