Guideline for attributes #52
Replies: 3 comments 3 replies
-
|
I think your suggestion is alright. I only slightly disagree on get and set. I don't mind so much having get/set functions instead of properties, even if it is not so Pythonic. Maybe the guidelines should be added to CONTRIBUTING.md or to some other visible place. |
Beta Was this translation helpful? Give feedback.
-
|
@JeanLucPons What do you think about this? |
Beta Was this translation helpful? Give feedback.
-
|
I'm not sure to fully understand, do you want to add some # Set up the chromaticy monitor (override config settings)
CM = SR.get_chromaticity_monitor("CHROMATICITY_MONITOR")
CM.n_step =3 # 3 point for chroma fit
CM.n_avg_meas = 1 # No averaging`And in the model you |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When going through the code I found different ways of how attributes are implemented and I also wasn't entirely sure what to go for myself when doing changes. So I thought deciding on a guideline would be good.
This is my suggestion:
For attributes that are meant to be public to users or other classes and where no special logic is needed for getting/settings, use regular attributes, e.g.
self.x.For attributes that are intended to be private to a class and never called by another class use single underscore, e.g.
self._x.'If another class calls such an attribute, it means the implementation is wrong and should be modified.
For attributes that need special logic for getting/setting, use single underscore + property decorator for getter/setter. Only make functions like get_something and set_something if there is a specific use case for it.
Never use double underscore unless you have a specific use case where it is necessary. This is because name mangling make the code more difficult to understand and debug for non-expert Python programmers.
Beta Was this translation helpful? Give feedback.
All reactions