[chirp_devel] Naming convention for class fields?
Stuart Longland VK4MSL
Mon May 15 17:42:47 PDT 2023
On 16/5/23 10:32, Craig Jones via chirp_devel wrote:
> FYI: I stand corrected. I reread PEP8. One leading underscore is meant
> to say protected, not private. Thus, it is part of the subclass API.
> It's double leading underscores that means completely private.
Double leading underscore normally refers to things that are special to
Python. Things like `__len__` (implements `len()`), `__repr__`, etc
which implement various operators.
Or deeply internal things like `__slots__` which is used to define what
attributes a class instance has so it can be "set in stone" as a
`struct` rather than using a `dict` implementation which consumes more
memory.
In general:
- leading underscore → private/protected (not enforced)
- UPPER_CASE_WITH_UNDERSCORES → constant
`_model` as a class attribute suggests the attribute might sometimes
change to reference something else, but it is otherwise
private/protected. `_MODEL` might be better if we know it won't change
-- but the interpreter does not care; such designations are just for us
meat bags to better understand what's going on.
--
Stuart Longland (aka Redhatter, VK4MSL)
I haven't lost my mind...
...it's backed up on a tape somewhere.
More information about the chirp_devel
mailing list