Skip to content

Commit e246714

Browse files
committed
Add pragma: no cover to unreachable code paths
1 parent b7f31be commit e246714

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/datamodel_code_generator/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def validate_keyword_only(self: Self) -> Self: # pyright: ignore[reportRedeclar
374374
and output_model_type == DataModelType.DataclassesDataclass
375375
and not python_target.has_kw_only_dataclass
376376
):
377-
raise Error(self.__validate_keyword_only_err)
377+
raise Error(self.__validate_keyword_only_err) # pragma: no cover
378378
return self
379379

380380
@model_validator() # pyright: ignore[reportArgumentType]

src/datamodel_code_generator/model/msgspec.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def new_imports(self: DataModelFieldBaseT) -> tuple[Import, ...]:
9696
extra_imports.append(IMPORT_MSGSPEC_META)
9797
if not self.required and not self.nullable:
9898
extra_imports.append(IMPORT_MSGSPEC_UNSETTYPE)
99-
if not self.data_type.use_union_operator:
99+
if not self.data_type.use_union_operator: # pragma: no cover
100100
extra_imports.append(IMPORT_UNION)
101101
if self.default is None or self.default is UNDEFINED:
102102
extra_imports.append(IMPORT_MSGSPEC_UNSET)
@@ -228,22 +228,22 @@ def get_neither_required_nor_nullable_type(type_: str, use_union_operator: bool)
228228
return UNSET_TYPE
229229
if use_union_operator:
230230
return UNION_OPERATOR_DELIMITER.join((type_, UNSET_TYPE))
231-
if type_.startswith(UNION_PREFIX):
231+
if type_.startswith(UNION_PREFIX): # pragma: no cover
232232
return f"{type_[:-1]}{UNION_DELIMITER}{UNSET_TYPE}]"
233-
return f"{UNION_PREFIX}{type_}{UNION_DELIMITER}{UNSET_TYPE}]"
233+
return f"{UNION_PREFIX}{type_}{UNION_DELIMITER}{UNSET_TYPE}]" # pragma: no cover
234234

235235

236236
@lru_cache
237237
def _add_unset_type(type_: str, use_union_operator: bool) -> str: # noqa: FBT001
238238
"""Add UnsetType to a type hint without removing None."""
239239
if use_union_operator:
240240
return f"{type_}{UNION_OPERATOR_DELIMITER}{UNSET_TYPE}"
241-
if type_.startswith(UNION_PREFIX):
241+
if type_.startswith(UNION_PREFIX): # pragma: no cover
242242
return f"{type_[:-1]}{UNION_DELIMITER}{UNSET_TYPE}]"
243243
if type_.startswith(OPTIONAL_PREFIX): # pragma: no cover
244244
inner_type = type_[len(OPTIONAL_PREFIX) : -1]
245245
return f"{UNION_PREFIX}{inner_type}{UNION_DELIMITER}{NONE}{UNION_DELIMITER}{UNSET_TYPE}]"
246-
return f"{UNION_PREFIX}{type_}{UNION_DELIMITER}{UNSET_TYPE}]"
246+
return f"{UNION_PREFIX}{type_}{UNION_DELIMITER}{UNSET_TYPE}]" # pragma: no cover
247247

248248

249249
@import_extender
@@ -407,7 +407,7 @@ def annotated(self) -> str | None: # noqa: PLR0911
407407
"""
408408
if self.extras.get("is_classvar"):
409409
meta = self._get_meta_string()
410-
if self.use_annotated and meta:
410+
if self.use_annotated and meta: # pragma: no cover
411411
return f"ClassVar[Annotated[{self.type_hint}, {meta}]]"
412412
return f"ClassVar[{self.type_hint}]"
413413

@@ -438,7 +438,7 @@ def needs_annotated_import(self) -> bool:
438438
"""
439439
if not self.annotated:
440440
return False
441-
if self.extras.get("is_classvar"):
441+
if self.extras.get("is_classvar"): # pragma: no cover
442442
return self.use_annotated and self._get_meta_string() is not None
443443
return True
444444

0 commit comments

Comments
 (0)