Skip to content

Commit 39856a5

Browse files
lint fix
1 parent 6d61ec8 commit 39856a5

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/eligibility_signposting_api/model/campaign_config.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,18 @@ class Iteration(BaseModel):
274274
def parse_dates(cls, v: str | date) -> date:
275275
if isinstance(v, date):
276276
return v
277-
if not re.fullmatch(r"\d{8}", str(v)):
278-
raise ValueError(f"Invalid format: {v}. Must be YYYYMMDD with 8 digits.")
277+
278+
v_str = str(v)
279+
280+
if not re.fullmatch(r"\d{8}", v_str):
281+
msg = f"Invalid format: {v_str}. Must be YYYYMMDD with 8 digits."
282+
raise ValueError(msg)
283+
279284
try:
280-
return datetime.strptime(str(v), "%Y%m%d").date() # noqa: DTZ007
281-
except ValueError:
282-
raise ValueError(f"Invalid date value: {v}. Must be a valid calendar date in YYYYMMDD format.")
285+
return datetime.strptime(v_str, "%Y%m%d").date() # noqa: DTZ007
286+
except ValueError as err:
287+
msg = f"Invalid date value: {v_str}. Must be a valid calendar date in YYYYMMDD format."
288+
raise ValueError(msg) from err
283289

284290
@field_serializer("iteration_date", when_used="always")
285291
@staticmethod
@@ -322,12 +328,18 @@ class CampaignConfig(BaseModel):
322328
def parse_dates(cls, v: str | date) -> date:
323329
if isinstance(v, date):
324330
return v
325-
if not re.fullmatch(r"\d{8}", str(v)):
326-
raise ValueError(f"Invalid format: {v}. Must be YYYYMMDD with 8 digits.")
331+
332+
v_str = str(v)
333+
334+
if not re.fullmatch(r"\d{8}", v_str):
335+
msg = f"Invalid format: {v_str}. Must be YYYYMMDD with 8 digits."
336+
raise ValueError(msg)
337+
327338
try:
328-
return datetime.strptime(str(v), "%Y%m%d").date() # noqa: DTZ007
329-
except ValueError:
330-
raise ValueError(f"Invalid date value: {v}. Must be a valid calendar date in YYYYMMDD format.")
339+
return datetime.strptime(v_str, "%Y%m%d").date() # noqa: DTZ007
340+
except ValueError as err:
341+
msg = f"Invalid date value: {v_str}. Must be a valid calendar date in YYYYMMDD format."
342+
raise ValueError(msg) from err
331343

332344
@field_serializer("start_date", "end_date", when_used="always")
333345
@staticmethod

src/rules_validation_api/validators/iteration_rules_validator.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def check_cohort_label_for_non_f_and_s_types(self) -> typing.Self:
2727
allowed_types = {RuleType("F"), RuleType("S")}
2828
if self.cohort_label is not None and self.type not in allowed_types:
2929
msg = (
30-
f"CohortLabel is only allowed for rule types F and S. "
30+
"CohortLabel is only allowed for rule types F and S. "
3131
f"Found type: {self.type} with cohort_label: {self.cohort_label}"
3232
)
3333
raise ValueError(msg)
@@ -39,12 +39,14 @@ def validate_attribute_name_is_optional_only_for_cohort_attribute_level(self) ->
3939
return self
4040
if self.attribute_level == RuleAttributeLevel.COHORT:
4141
return self
42-
raise ValueError(f"AttributeName must be set where AttributeLevel is {self.attribute_level} .")
42+
msg = f"AttributeName must be set where AttributeLevel is {self.attribute_level}."
43+
raise ValueError(msg)
4344

4445
@model_validator(mode="after")
4546
def validate_attribute_target_is_mandatory_for_target_attribute_level(self) -> typing.Self:
4647
if self.attribute_target:
4748
return self
4849
if self.attribute_level != RuleAttributeLevel.TARGET:
4950
return self
50-
raise ValueError(f"AttributeTarget is mandatory where AttributeLevel is {self.attribute_level}.")
51+
msg = f"AttributeTarget is mandatory where AttributeLevel is {self.attribute_level}."
52+
raise ValueError(msg)

0 commit comments

Comments
 (0)