mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-24 18:10:02 +02:00
feat: adding utils.helper
This commit is contained in:
parent
bb48ba237d
commit
8460759a31
@ -1,3 +1,7 @@
|
|||||||
|
from .helpers import get_class_and_instance_attributes
|
||||||
from .warnings import warn_if_instance_class_does_not_inherit_from_DataService
|
from .warnings import warn_if_instance_class_does_not_inherit_from_DataService
|
||||||
|
|
||||||
__all__ = ["warn_if_instance_class_does_not_inherit_from_DataService"]
|
__all__ = [
|
||||||
|
"warn_if_instance_class_does_not_inherit_from_DataService",
|
||||||
|
"get_class_and_instance_attributes",
|
||||||
|
]
|
||||||
|
17
src/pyDataInterface/utils/helpers.py
Normal file
17
src/pyDataInterface/utils/helpers.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from itertools import chain
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
def get_class_and_instance_attributes(obj: object) -> dict[str, Any]:
|
||||||
|
"""Dictionary containing all attributes (both instance and class level) of a
|
||||||
|
given object.
|
||||||
|
|
||||||
|
If an attribute exists at both the instance and class level,the value from the
|
||||||
|
instance attribute takes precedence.
|
||||||
|
The __root__ object is removed as this will lead to endless recursion in the for
|
||||||
|
loops.
|
||||||
|
"""
|
||||||
|
|
||||||
|
attrs = dict(chain(type(obj).__dict__.items(), obj.__dict__.items()))
|
||||||
|
attrs.pop("__root__")
|
||||||
|
return attrs
|
Loading…
x
Reference in New Issue
Block a user