Skip to content

Commit a621da1

Browse files
committed
Faster and more reliable path matching.
1 parent a62abe8 commit a621da1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

c8y_api/model/_base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,16 @@ def get(self, path: str, default=None) -> Any:
525525
segments = path.split('.')
526526
value = self
527527
for segment in segments:
528-
if segment in value:
528+
# try to drill down (assuming dict-like)
529+
try:
529530
value = value[segment]
530531
continue
532+
except (KeyError, TypeError):
533+
pass
534+
# if the segment is an actual attribute it should be the target
531535
if hasattr(value, segment):
532536
return value.__getattribute__(segment)
537+
# otherwise use the default
533538
return default
534539
return value
535540

0 commit comments

Comments
 (0)