Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/ga4gh/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
StringConstraints,
model_validator,
)
from typing_extensions import Self

from ga4gh.core.identifiers import GA4GH_IR_REGEXP

Expand Down Expand Up @@ -226,13 +225,15 @@
description="A list of mappings to concepts in terminologies or code systems. Each mapping should include a coding and a relation.",
)

@model_validator(mode="after")
def require_name_or_primary_coding(self) -> Self:
@model_validator(mode="before")
@classmethod
def require_name_or_primary_coding(cls, values: Any) -> Any:

Check failure on line 230 in src/ga4gh/core/models.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (ANN401)

src/ga4gh/core/models.py:230:61: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `require_name_or_primary_coding`

Check failure on line 230 in src/ga4gh/core/models.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (ANN401)

src/ga4gh/core/models.py:230:53: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `values`
"""Ensure that ``name`` or ``primaryCoding`` is provided"""
if self.primaryCoding is None and self.name is None:
err_msg = "One of `name` or `primaryCoding` must be provided."
raise ValueError(err_msg)
return self
if isinstance(values, dict):
if values.get("primaryCoding") is None and values.get("name") is None:

Check failure on line 233 in src/ga4gh/core/models.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (SIM102)

src/ga4gh/core/models.py:232:9: SIM102 Use a single `if` statement instead of nested `if` statements
err_msg = "One of `name` or `primaryCoding` must be provided."
raise ValueError(err_msg)
return values


Element.model_rebuild()
Expand Down
Loading