Skip to content

Commit

Permalink
refactor: Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: micha91 <[email protected]>
  • Loading branch information
ewuerger and micha91 authored Jan 23, 2025
1 parent 715690c commit 9759b78
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions capella2polarion/converters/converter_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class LinkConfig:
reverse_field: str = ""

@staticmethod
def _force_config(
def generate_links_configs(
links: list[str | dict[str, t.Any]], role_prefix: str = ""
) -> list[LinkConfig]:
"""Generate LinkConfigs based on a list of strings or a configuration dict."""
result: list[LinkConfig] = []
for link in links:
if isinstance(link, str):
Expand Down Expand Up @@ -119,20 +120,20 @@ def _filter_config(
filtered_config = {}
assert isinstance(converters, dict)
for name, params in converters.items():
params = params or {}
if name not in custom_converters:
logger.error("Unknown converter in config %r", name)
continue

if name in ("add_context_diagram", "add_tree_diagram"):
assert isinstance(params, dict)
params = _filter_context_diagram_config(params)

if name in ("add_attributes",):
assert isinstance(params, list) # type: ignore[unreachable]
params = {"attributes": params} # type: ignore[unreachable]

filtered_config[name] = params
match name:
case "add_context_diagram" | "add_tree_diagram":
params = params or {}
if isinstance(params, dict):
filtered_config[name] = _filter_context_diagram_config(params)
else:
logger.error("Converter %r must be configured with dict type parameters", name)
case "add_attributes":
if isinstance(params, list):
filtered_config[name] = {"attributes": params}
else:
logger.error("Converter %r must be configured with list type parameters", name)
case _:
filtered_config[name] = params

return filtered_config

Expand Down

0 comments on commit 9759b78

Please sign in to comment.