Skip to content

Commit

Permalink
refactor: use a defaults dictionary instead of multiple if elses as s…
Browse files Browse the repository at this point in the history
…uggested in the review
  • Loading branch information
micha91 committed Jan 17, 2024
1 parent 489b40a commit 13eef53
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions capella2polarion/connectors/polarion_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
logger = logging.getLogger(__name__)


DEFAULT_ATTRIBUTE_VALUES: dict[type, t.Any] = {
str: "",
int: 0,
bool: False,
}


class PolarionWorkerParams:
"""Container for Polarion Params."""

Expand Down Expand Up @@ -179,16 +186,12 @@ def patch_work_item(

# If additional fields were present in the past, but aren't anymore,
# we have to set them to an empty value manually
defaults = DEFAULT_ATTRIBUTE_VALUES
for attribute, value in old.additional_attributes.items():
if attribute not in new.additional_attributes:
new_value: t.Any = None
if isinstance(value, str):
new_value = ""
elif isinstance(value, int):
new_value = 0
elif isinstance(value, bool):
new_value = False
new.additional_attributes[attribute] = new_value
new.additional_attributes[attribute] = defaults.get(
type(value)
)
elif new.additional_attributes[attribute] == value:
del new.additional_attributes[attribute]

Expand Down

0 comments on commit 13eef53

Please sign in to comment.