Skip to content

Commit

Permalink
refactor: resolve Pylance warnings (#366)
Browse files Browse the repository at this point in the history
* replace constr with Annotated and StringConstraints
  • Loading branch information
korikuzma authored Jul 19, 2024
1 parent 14b7527 commit ba9cc04
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/gene/schemas.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Contains data models for representing VICC normalized gene records."""

from enum import Enum, IntEnum
from typing import Literal
from typing import Annotated, Literal

from ga4gh.core import domain_models
from ga4gh.vrs import models
Expand All @@ -11,12 +11,12 @@
StrictBool,
StrictInt,
StrictStr,
constr,
StringConstraints,
)

from gene import __version__

CURIE = constr(pattern=r"^\w[^:]*:.+$")
CURIE_REGEX = r"^\w[^:]*:.+$"


class SymbolStatus(str, Enum):
Expand Down Expand Up @@ -69,15 +69,17 @@ class GeneSequenceLocation(BaseModel):
type: Literal["SequenceLocation"] = "SequenceLocation"
start: StrictInt
end: StrictInt
sequence_id: constr(pattern=r"^ga4gh:SQ.[0-9A-Za-z_\-]{32}$")
sequence_id: Annotated[
str, StringConstraints(pattern=r"^ga4gh:SQ.[0-9A-Za-z_\-]{32}$")
]


class BaseGene(BaseModel):
"""Base gene model. Provide shared resources for records produced by
/search and /normalize_unmerged.
"""

concept_id: CURIE
concept_id: Annotated[str, StringConstraints(pattern=CURIE_REGEX)]
symbol: StrictStr
symbol_status: SymbolStatus | None = None
label: StrictStr | None = None
Expand All @@ -86,8 +88,8 @@ class BaseGene(BaseModel):
locations: list[models.SequenceLocation] | list[GeneSequenceLocation] = []
aliases: list[StrictStr] = []
previous_symbols: list[StrictStr] = []
xrefs: list[CURIE] = []
associated_with: list[CURIE] = []
xrefs: list[Annotated[str, StringConstraints(pattern=CURIE_REGEX)]] = []
associated_with: list[Annotated[str, StringConstraints(pattern=CURIE_REGEX)]] = []
gene_type: StrictStr | None = None


Expand Down Expand Up @@ -460,7 +462,9 @@ class UnmergedNormalizationService(BaseNormalizationService):
attributes.
"""

normalized_concept_id: CURIE | None = None
normalized_concept_id: (
Annotated[str, StringConstraints(pattern=CURIE_REGEX)] | None
) = None
source_matches: dict[SourceName, MatchesNormalized]

model_config = ConfigDict(
Expand Down

0 comments on commit ba9cc04

Please sign in to comment.