MCPcopy
hub / github.com/github/spec-kit / _resolve_dot_path

Function _resolve_dot_path

src/specify_cli/workflows/expressions.py:97–123  ·  view source on GitHub ↗

Resolve a dotted path like ``steps.specify.output.file`` against *obj*. Supports dict key access and list indexing (e.g., ``task_list[0]``).

(obj: Any, path: str)

Source from the content-addressed store, hash-verified

95
96
97def _resolve_dot_path(obj: Any, path: str) -> Any:
98 """Resolve a dotted path like ``steps.specify.output.file`` against *obj*.
99
100 Supports dict key access and list indexing (e.g., ``task_list[0]``).
101 """
102 parts = path.split(".")
103 current = obj
104 for part in parts:
105 # Handle list indexing: name[0]
106 idx_match = re.match(r"^([\w-]+)\[(\d+)\]$", part)
107 if idx_match:
108 key, idx = idx_match.group(1), int(idx_match.group(2))
109 if isinstance(current, dict):
110 current = current.get(key)
111 else:
112 return None
113 if isinstance(current, list) and 0 <= idx < len(current):
114 current = current[idx]
115 else:
116 return None
117 elif isinstance(current, dict):
118 current = current.get(part)
119 else:
120 return None
121 if current is None:
122 return None
123 return current
124
125
126def _build_namespace(context: Any) -> dict[str, Any]:

Callers 1

Calls 1

getMethod · 0.45

Tested by

no test coverage detected