Split a path around "." into a tuple of strings and ints.
If a sub-path is quoted, it will be returned as a full non-split string.
PARAMETER |
DESCRIPTION |
path |
TYPE:
str
|
Source code in confit/utils/collections.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 | def split_path(path: str) -> Tuple[Union[int, str]]:
"""
Split a path around "." into a tuple of strings and ints.
If a sub-path is quoted, it will be returned as a full non-split string.
Parameters
----------
path: str
Returns
-------
"""
offset = 0
result = []
for match in re.finditer(KEY_PART, str(path)):
assert match.start() == offset, f"Malformed path: {path!r} in config"
offset = match.end()
part = next((g for g in match.groups() if g is not None))
result.append(int(part) if part.isdigit() else part)
if offset == len(path):
break
return tuple(result)
|