From 91f7496a4a3862e856618cf23cf16d3c299d75b9 Mon Sep 17 00:00:00 2001 From: Richard Lin Date: Mon, 22 Apr 2024 16:36:00 -0700 Subject: [PATCH] local_path_to_str_list --- edgir/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/edgir/__init__.py b/edgir/__init__.py index 376b667c3..d5459e70b 100644 --- a/edgir/__init__.py +++ b/edgir/__init__.py @@ -67,7 +67,7 @@ def valuelit_to_lit(expr: ValueLit) -> LitTypes: elif expr.HasField('integer'): return expr.integer.val elif expr.HasField('range') and \ - expr.range.minimum.HasField('floating') and expr.range.maximum.HasField('floating'): + expr.range.minimum.HasField('floating') and expr.range.maximum.HasField('floating'): from edg_core.Range import Range # TODO fix me, this prevents a circular import return Range(expr.range.minimum.floating.val, expr.range.maximum.floating.val) elif expr.HasField('text'): @@ -169,7 +169,8 @@ def AssignRef(dst: Iterable[str], src: Iterable[str]) -> ValueExpr: return pb -def local_path_to_str(path: LocalPath) -> str: +def local_path_to_str_list(path: LocalPath) -> List[str]: + """Convert a LocalPath to a list of its components. Reserved params are presented as strings.""" def step_to_str(step: LocalStep) -> str: if step.HasField('name'): return step.name @@ -180,8 +181,10 @@ def step_to_str(step: LocalStep) -> str: }[step.reserved_param] else: raise ValueError(f"unknown step {step}") + return [step_to_str(step) for step in path.steps] - return '.'.join([step_to_str(step) for step in path.steps]) +def local_path_to_str(path: LocalPath) -> str: + return '.'.join(local_path_to_str_list(path)) @overload def add_pair(pb: RepeatedCompositeFieldContainer[NamedPortLike], name: str) -> PortLike: ...