-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpath_mapper.py
More file actions
29 lines (23 loc) · 904 Bytes
/
Copy pathpath_mapper.py
File metadata and controls
29 lines (23 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class MapPath:
"""Represents a recursive path to an object attribute using dot notation (e.g., ob.attribute.sub_attribute)."""
def __init__(self, path: str):
if "." not in path:
raise ValueError(f"Invalid path: '{path}' does not contain '.'")
self.path = path
self.attributes = path.split(".")
if not len(self.attributes) >= 1:
raise ValueError(
f"Invalid path: '{path}'. Can´t reference to object attribute."
)
self._obj_prefix: str | None = None
@property
def obj_prefix(self):
return self._obj_prefix
@obj_prefix.setter
def obj_prefix(self, src_cls_name: str) -> None:
"""Setter for obj_prefix."""
self._obj_prefix = src_cls_name
def __call__(self):
return self.attributes
def __repr__(self):
return f"MapPath({self.attributes})"