From e6389788f7b412544879d70f73877707469ca6fe Mon Sep 17 00:00:00 2001 From: ewuerger Date: Tue, 12 Dec 2023 14:24:57 +0100 Subject: [PATCH] refactor: Apply requested change from review to `patch_work_items` --- capella2polarion/elements/__init__.py | 6 +----- capella2polarion/elements/serialize.py | 10 +++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/capella2polarion/elements/__init__.py b/capella2polarion/elements/__init__.py index a98126c9..ba119130 100644 --- a/capella2polarion/elements/__init__.py +++ b/capella2polarion/elements/__init__.py @@ -148,9 +148,7 @@ def patch_work_items(ctx: dict[str, t.Any]) -> None: objects = ctx["MODEL"].diagrams obj = objects.by_uuid(uuid) - work_item: serialize.CapellaWorkItem - if (work_item := ctx["WORK_ITEMS"][uuid]) is None: - continue + work_item: serialize.CapellaWorkItem = ctx["WORK_ITEMS"][uuid] old_work_item: serialize.CapellaWorkItem = ctx["POLARION_WI_MAP"][uuid] links = element.create_links(obj, ctx) @@ -161,8 +159,6 @@ def patch_work_items(ctx: dict[str, t.Any]) -> None: for uuid in uuids: new_work_item: serialize.CapellaWorkItem = ctx["WORK_ITEMS"][uuid] - if (new_work_item := ctx["WORK_ITEMS"][uuid]) is None: - continue old_work_item = ctx["POLARION_WI_MAP"][uuid] if old_work_item.id in back_links: element.create_grouped_back_link_fields( diff --git a/capella2polarion/elements/serialize.py b/capella2polarion/elements/serialize.py index 91c923cb..286e3946 100644 --- a/capella2polarion/elements/serialize.py +++ b/capella2polarion/elements/serialize.py @@ -221,14 +221,14 @@ def replace_markup( uuid = match.group(1) try: ctx["MODEL"].by_uuid(uuid) - if pid := ctx["POLARION_ID_MAP"].get(uuid): - referenced_uuids.append(uuid) - return POLARION_WORK_ITEM_URL.format(pid=pid) - logger.warning("Found reference to non-existing work item: %r", uuid) - return match.group(default_group) except KeyError: logger.error("Found link to non-existing model element: %r", uuid) return strike_through(match.group(default_group)) + if pid := ctx["POLARION_ID_MAP"].get(uuid): + referenced_uuids.append(uuid) + return POLARION_WORK_ITEM_URL.format(pid=pid) + logger.warning("Found reference to non-existing work item: %r", uuid) + return match.group(default_group) def include_pre_and_post_condition(