class NiceClass():
some_value = SomeObject(...)
some_other_value = SomeOtherObject(...)
@classmethod
def get_all_vars(cls):
...
I want get_all_vars()
to return [SomeObject(...), SomeOtherObject(...)]
, or more specifically, the values of the variables in cls
.
Solutions tried that didn't work out for me:
return [cls.some_value, cls.some_other_value, ...]
(requires listing the variable manually)- subclassing
Enum
then usinglist(cls)
(requires usingsome_value.value
to access the value elsewhere in the program, also type hinting would be a mess) - namedtuples (nope not touching that subject, heard it was much more complicated than
Enum
) [value for key, value in vars(cls).items() if not callable(value) and not key.startswith("__")]
(too hacky due to usingvars(cls)
, also for some reason it also includesget_all_vars
due to it being aclassmethod
)