Skip to content

Commit 15bd9f3

Browse files
authored
chore: use keyword default arg in pydantic models (#471)
Using the positional arg makes some type checkers go nutso if you omit the arg This is a fix we've mostly done elsewhere but we've apparently missed these instances. Shouldn't have any runtime effects, just changes dev experience.
1 parent 71d0050 commit 15bd9f3

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

src/cool_seq_tool/mappers/exon_genomic_coords.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TxSegment(BaseModelForbidExtra):
6363

6464
exon_ord: StrictInt = Field(..., description="Exon number. 0-based.")
6565
offset: StrictInt = Field(
66-
0,
66+
default=0,
6767
description="The value added to or subtracted from the `genomic_location` to find the start or end of an exon.",
6868
)
6969
genomic_location: SequenceLocation = Field(
@@ -110,19 +110,23 @@ def check_seg_pos(cls, values: dict) -> dict: # noqa: N805
110110
class GenomicTxSeg(BaseModelForbidExtra):
111111
"""Model for representing a boundary for a transcript segment."""
112112

113-
seg: TxSegment | None = Field(None, description="Transcript segment.")
113+
seg: TxSegment | None = Field(default=None, description="Transcript segment.")
114114
gene: StrictStr | None = Field(
115-
None, description="Valid, case-sensitive HGNC gene symbol."
115+
default=None, description="Valid, case-sensitive HGNC gene symbol."
116+
)
117+
genomic_ac: StrictStr | None = Field(
118+
default=None, description="RefSeq genomic accession."
119+
)
120+
tx_ac: StrictStr | None = Field(
121+
default=None, description="RefSeq transcript accession."
116122
)
117-
genomic_ac: StrictStr | None = Field(None, description="RefSeq genomic accession.")
118-
tx_ac: StrictStr | None = Field(None, description="RefSeq transcript accession.")
119123
tx_status: TranscriptPriority | None = Field(
120-
None, description="Transcript priority for RefSeq transcript accession"
124+
default=None, description="Transcript priority for RefSeq transcript accession"
121125
)
122126
strand: Strand | None = Field(
123-
None, description="The strand that the transcript accession exists on."
127+
default=None, description="The strand that the transcript accession exists on."
124128
)
125-
errors: list[StrictStr] = Field([], description="Error messages.")
129+
errors: list[StrictStr] = Field(default=[], description="Error messages.")
126130

127131
@model_validator(mode="before")
128132
def check_errors(cls, values: dict) -> dict: # noqa: N805
@@ -175,19 +179,27 @@ class GenomicTxSegService(BaseModelForbidExtra):
175179
"""Service model for genomic and transcript data."""
176180

177181
gene: StrictStr | None = Field(
178-
None, description="Valid, case-sensitive HGNC gene symbol."
182+
default=None, description="Valid, case-sensitive HGNC gene symbol."
183+
)
184+
genomic_ac: StrictStr | None = Field(
185+
default=None, description="RefSeq genomic accession."
186+
)
187+
tx_ac: StrictStr | None = Field(
188+
default=None, description="RefSeq transcript accession."
179189
)
180-
genomic_ac: StrictStr | None = Field(None, description="RefSeq genomic accession.")
181-
tx_ac: StrictStr | None = Field(None, description="RefSeq transcript accession.")
182190
tx_status: TranscriptPriority | None = Field(
183-
None, description="Transcript priority for RefSeq transcript accession"
191+
default=None, description="Transcript priority for RefSeq transcript accession"
184192
)
185193
strand: Strand | None = Field(
186-
None, description="The strand that the transcript exists on."
194+
default=None, description="The strand that the transcript exists on."
195+
)
196+
seg_start: TxSegment | None = Field(
197+
default=None, description="Start transcript segment."
198+
)
199+
seg_end: TxSegment | None = Field(
200+
default=None, description="End transcript segment."
187201
)
188-
seg_start: TxSegment | None = Field(None, description="Start transcript segment.")
189-
seg_end: TxSegment | None = Field(None, description="End transcript segment.")
190-
errors: list[StrictStr] = Field([], description="Error messages.")
202+
errors: list[StrictStr] = Field(default=[], description="Error messages.")
191203
service_meta: ServiceMeta = Field(..., description="Service metadata.")
192204

193205
@model_validator(mode="before")

0 commit comments

Comments
 (0)