Skip to content

Commit 4f45c5b

Browse files
authored
chore: make optional fields visible to type checkers (#583)
1 parent 2d11ba3 commit 4f45c5b

2 files changed

Lines changed: 58 additions & 46 deletions

File tree

src/ga4gh/core/models.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,22 @@ class Entity(BaseModel, ABC):
9494
"""
9595

9696
id: str | None = Field(
97-
None,
97+
default=None,
9898
description="The 'logical' identifier of the Entity in the system of record, e.g. a UUID. This 'id' is unique within a given system, but may or may not be globally unique outside the system. It is used within a system to reference an object from another.",
9999
)
100100
type: str = Field(
101101
...,
102102
description="The name of the class that is instantiated by a data object representing the Entity.",
103103
)
104-
name: str | None = Field(None, description="A primary name for the entity.")
104+
name: str | None = Field(default=None, description="A primary name for the entity.")
105105
description: str | None = Field(
106-
None, description="A free-text description of the Entity."
106+
default=None, description="A free-text description of the Entity."
107107
)
108108
aliases: list[str] | None = Field(
109-
None, description="Alternative name(s) for the Entity."
109+
default=None, description="Alternative name(s) for the Entity."
110110
)
111111
extensions: list[Extension] | None = Field(
112-
None,
112+
default=None,
113113
description="A list of extensions to the Entity, that allow for capture of information not directly supported by elements defined in the model.",
114114
)
115115

@@ -121,11 +121,11 @@ class Element(BaseModel, ABC):
121121
"""
122122

123123
id: str | None = Field(
124-
None,
124+
default=None,
125125
description="The 'logical' identifier of the data element in the system of record, e.g. a UUID. This 'id' is unique within a given system, but may or may not be globally unique outside the system. It is used within a system to reference an object from another.",
126126
)
127127
extensions: list[Extension] | None = Field(
128-
None,
128+
default=None,
129129
description="A list of extensions to the Entity, that allow for capture of information not directly supported by elements defined in the model.",
130130
)
131131

@@ -141,20 +141,20 @@ class Coding(Element, BaseModelForbidExtra):
141141
"""
142142

143143
name: str | None = Field(
144-
None,
144+
default=None,
145145
description="The human-readable name for the coded concept, as defined by the code system.",
146146
)
147147
system: str = Field(
148148
...,
149149
description="The terminology/code system that defined the code. May be reported as a free-text name (e.g. 'Sequence Ontology'), but it is preferable to provide a uri/url for the system.",
150150
)
151151
systemVersion: str | None = Field( # noqa: N815
152-
None,
152+
default=None,
153153
description="Version of the terminology or code system that provided the code.",
154154
)
155155
code: code # Cannot use Field due to PydanticUserError: field name and type annotation must not clash.
156156
iris: list[iriReference] | None = Field(
157-
None,
157+
default=None,
158158
description="A list of IRIs that are associated with the coding. This can be used to provide additional context or to link to additional information about the concept.",
159159
)
160160

@@ -191,7 +191,7 @@ class Extension(Element, BaseModelForbidExtra):
191191
description="The value of the Extension - can be any primitive or structured object",
192192
)
193193
description: str | None = Field(
194-
None,
194+
default=None,
195195
description="A description of the meaning or utility of the Extension, to explain the type of information it is meant to hold.",
196196
)
197197

@@ -200,16 +200,18 @@ class MappableConcept(Element, BaseModelForbidExtra):
200200
"""A concept based on a primaryCoding and/or name that may be mapped to one or more other `Codings`."""
201201

202202
conceptType: str | None = Field( # noqa: N815
203-
None,
203+
default=None,
204204
description="A term indicating the type of concept being represented by the MappableConcept.",
205205
)
206-
name: str | None = Field(None, description="A primary name for the concept.")
206+
name: str | None = Field(
207+
default=None, description="A primary name for the concept."
208+
)
207209
primaryCoding: Coding | None = Field( # noqa: N815
208-
None,
210+
default=None,
209211
description="A primary coding for the concept.",
210212
)
211213
mappings: list[ConceptMapping] | None = Field(
212-
None,
214+
default=None,
213215
description="A list of mappings to concepts in terminologies or code systems. Each mapping should include a coding and a relation.",
214216
)
215217

src/ga4gh/vrs/models.py

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class Ga4ghIdentifiableObject(_ValueObject, ABC):
276276
digest: (
277277
Annotated[str, StringConstraints(pattern=r"^[0-9A-Za-z_\-]{32}$")] | None
278278
) = Field(
279-
None,
279+
default=None,
280280
description="A sha512t24u digest created using the VRS Computed Identifier algorithm.",
281281
)
282282

@@ -397,7 +397,7 @@ class Expression(Element, BaseModelForbidExtra):
397397
description="The expression of the variation in the specified syntax. The value should be a valid expression in the specified syntax.",
398398
)
399399
syntax_version: str | None = Field(
400-
None,
400+
default=None,
401401
description="The version of the syntax used to describe the variation. This is particularly important for HGVS expressions, as the syntax has evolved over time.",
402402
)
403403

@@ -480,9 +480,12 @@ class LengthExpression(_ValueObject, BaseModelForbidExtra):
480480
"""A sequence expressed only by its length."""
481481

482482
type: Literal["LengthExpression"] = Field(
483-
VrsType.LEN_EXPR.value, description=f'MUST be "{VrsType.LEN_EXPR.value}"'
483+
default=VrsType.LEN_EXPR.value,
484+
description=f'MUST be "{VrsType.LEN_EXPR.value}"',
485+
)
486+
length: Range | int | None = Field(
487+
default=None, description="The length of the sequence."
484488
)
485-
length: Range | int | None = Field(None, description="The length of the sequence.")
486489

487490
class ga4gh(_ValueObject.ga4gh):
488491
inherent = ["length", "type"]
@@ -492,14 +495,14 @@ class ReferenceLengthExpression(_ValueObject, BaseModelForbidExtra):
492495
"""An expression of a length of a sequence from a repeating reference."""
493496

494497
type: Literal["ReferenceLengthExpression"] = Field(
495-
VrsType.REF_LEN_EXPR.value,
498+
default=VrsType.REF_LEN_EXPR.value,
496499
description=f'MUST be "{VrsType.REF_LEN_EXPR.value}"',
497500
)
498501
length: Range | int = Field(
499502
..., description="The number of residues in the expressed sequence."
500503
)
501504
sequence: sequenceString | None = Field(
502-
None,
505+
default=None,
503506
description="the literal Sequence encoded by the Reference Length Expression.",
504507
)
505508
repeatSubunitLength: int = Field(
@@ -514,7 +517,7 @@ class LiteralSequenceExpression(_ValueObject, BaseModelForbidExtra):
514517
"""An explicit expression of a Sequence."""
515518

516519
type: Literal["LiteralSequenceExpression"] = Field(
517-
VrsType.LIT_SEQ_EXPR.value,
520+
default=VrsType.LIT_SEQ_EXPR.value,
518521
description=f'MUST be "{VrsType.LIT_SEQ_EXPR.value}"',
519522
)
520523
sequence: sequenceString = Field(..., description="the literal sequence")
@@ -534,7 +537,7 @@ class SequenceReference(_ValueObject, BaseModelForbidExtra):
534537
model_config = ConfigDict(use_enum_values=True)
535538

536539
type: Literal["SequenceReference"] = Field(
537-
VrsType.SEQ_REF.value, description=f'MUST be "{VrsType.SEQ_REF.value}"'
540+
default=VrsType.SEQ_REF.value, description=f'MUST be "{VrsType.SEQ_REF.value}"'
538541
)
539542
refgetAccession: Annotated[
540543
str, StringConstraints(pattern=r"^SQ.[0-9A-Za-z_\-]{32}$")
@@ -543,19 +546,19 @@ class SequenceReference(_ValueObject, BaseModelForbidExtra):
543546
description="A [GA4GH RefGet](http://samtools.github.io/hts-specs/refget.html) identifier for the referenced sequence, using the sha512t24u digest.",
544547
)
545548
residueAlphabet: ResidueAlphabet | None = Field(
546-
None,
549+
default=None,
547550
description='The interpretation of the character codes referred to by the refget accession, where "aa" specifies an amino acid character set, and "na" specifies a nucleic acid character set.',
548551
)
549552
circular: bool | None = Field(
550-
None,
553+
default=None,
551554
description="A boolean indicating whether the molecule represented by the sequence is circular (true) or linear (false).",
552555
)
553556
sequence: sequenceString | None = Field(
554-
None,
557+
default=None,
555558
description="A sequenceString that is a literal representation of the referenced sequence.",
556559
)
557560
moleculeType: MoleculeType | None = Field(
558-
None,
561+
default=None,
559562
description="Molecule types as [defined by RefSeq](https://www.ncbi.nlm.nih.gov/books/NBK21091/) (see Table 1). MUST be one of 'genomic', 'RNA', 'mRNA', or 'protein'.",
560563
)
561564

@@ -567,22 +570,22 @@ class SequenceLocation(Ga4ghIdentifiableObject, BaseModelForbidExtra):
567570
"""A `Location` defined by an interval on a `Sequence`."""
568571

569572
type: Literal["SequenceLocation"] = Field(
570-
VrsType.SEQ_LOC.value, description=f'MUST be "{VrsType.SEQ_LOC.value}"'
573+
default=VrsType.SEQ_LOC.value, description=f'MUST be "{VrsType.SEQ_LOC.value}"'
571574
)
572575
sequenceReference: iriReference | SequenceReference | None = Field(
573-
None,
576+
default=None,
574577
description="A reference to a SequenceReference on which the location is defined.",
575578
)
576579
start: Range | int | None = Field(
577-
None,
580+
default=None,
578581
description="The start coordinate or range of the SequenceLocation. The minimum value of this coordinate or range is 0. For locations on linear sequences, this MUST represent a coordinate or range less than or equal to the value of `end`. For circular sequences, `start` is greater than `end` when the location spans the sequence 0 coordinate.",
579582
)
580583
end: Range | int | None = Field(
581-
None,
584+
default=None,
582585
description="The end coordinate or range of the SequenceLocation. The minimum value of this coordinate or range is 0. For locations on linear sequences, this MUST represent a coordinate or range greater than or equal to the value of `start`. For circular sequences, `end` is less than `start` when the location spans the sequence 0 coordinate.",
583586
)
584587
sequence: sequenceString | None = Field(
585-
None,
588+
default=None,
586589
description="The literal sequence encoded by the `sequenceReference` at these coordinates.",
587590
)
588591

@@ -673,7 +676,7 @@ class Allele(_VariationBase, BaseModelForbidExtra):
673676
"""The state of a molecule at a `Location`."""
674677

675678
type: Literal["Allele"] = Field(
676-
VrsType.ALLELE.value, description=f'MUST be "{VrsType.ALLELE.value}"'
679+
default=VrsType.ALLELE.value, description=f'MUST be "{VrsType.ALLELE.value}"'
677680
)
678681
location: iriReference | SequenceLocation = Field(
679682
..., description="The location of the Allele"
@@ -717,7 +720,7 @@ class CisPhasedBlock(_VariationBase, BaseModelForbidExtra):
717720
"""An ordered set of co-occurring `Variation` on the same molecule."""
718721

719722
type: Literal["CisPhasedBlock"] = Field(
720-
VrsType.CIS_PHASED_BLOCK.value,
723+
default=VrsType.CIS_PHASED_BLOCK.value,
721724
description=f'MUST be "{VrsType.CIS_PHASED_BLOCK.value}"',
722725
)
723726
members: list[Allele | iriReference] = Field(
@@ -726,7 +729,7 @@ class CisPhasedBlock(_VariationBase, BaseModelForbidExtra):
726729
min_length=2,
727730
)
728731
sequenceReference: SequenceReference | None = Field(
729-
None,
732+
default=None,
730733
description="An optional Sequence Reference on which all of the in-cis Alleles are found. When defined, this may be used to implicitly define the `sequenceReference` attribute for each of the CisPhasedBlock member Alleles.",
731734
)
732735

@@ -751,7 +754,8 @@ class Adjacency(_VariationBase, BaseModelForbidExtra):
751754
"""
752755

753756
type: Literal["Adjacency"] = Field(
754-
VrsType.ADJACENCY.value, description=f'MUST be "{VrsType.ADJACENCY.value}".'
757+
default=VrsType.ADJACENCY.value,
758+
description=f'MUST be "{VrsType.ADJACENCY.value}".',
755759
)
756760
adjoinedSequences: list[iriReference | SequenceLocation] = Field(
757761
...,
@@ -761,9 +765,11 @@ class Adjacency(_VariationBase, BaseModelForbidExtra):
761765
)
762766
linker: (
763767
LiteralSequenceExpression | ReferenceLengthExpression | LengthExpression | None
764-
) = Field(None, description="The sequence found between adjoined sequences.")
768+
) = Field(
769+
default=None, description="The sequence found between adjoined sequences."
770+
)
765771
homology: bool | None = Field(
766-
None,
772+
default=None,
767773
description="A flag indicating if coordinate ambiguity in the adjoined sequences is from sequence homology (true) or other uncertainty, such as instrument ambiguity (false).",
768774
)
769775

@@ -793,7 +799,8 @@ class Terminus(_VariationBase, BaseModelForbidExtra):
793799
"""
794800

795801
type: Literal["Terminus"] = Field(
796-
VrsType.TERMINUS.value, description=f'MUST be "{VrsType.TERMINUS.value}".'
802+
default=VrsType.TERMINUS.value,
803+
description=f'MUST be "{VrsType.TERMINUS.value}".',
797804
)
798805
location: iriReference | SequenceLocation = Field(
799806
..., description="The location of the terminus."
@@ -812,15 +819,16 @@ class TraversalBlock(_ValueObject, BaseModelForbidExtra):
812819
model_config = ConfigDict(use_enum_values=True)
813820

814821
type: Literal["TraversalBlock"] = Field(
815-
VrsType.TRAVERSAL_BLOCK.value,
822+
default=VrsType.TRAVERSAL_BLOCK.value,
816823
description=f'MUST be "{VrsType.TRAVERSAL_BLOCK.value}".',
817824
)
818825
orientation: Orientation | None = Field(
819-
None, description="The orientation of the molecular variation component."
826+
default=None,
827+
description="The orientation of the molecular variation component.",
820828
)
821829

822830
component: Adjacency | None = Field(
823-
None, description="The unoriented molecular variation component."
831+
default=None, description="The unoriented molecular variation component."
824832
)
825833

826834
class ga4gh(_ValueObject.ga4gh):
@@ -833,7 +841,7 @@ class DerivativeMolecule(_VariationBase, BaseModelForbidExtra):
833841
"""
834842

835843
type: Literal["DerivativeMolecule"] = Field(
836-
VrsType.DERIVATIVE_MOL.value,
844+
default=VrsType.DERIVATIVE_MOL.value,
837845
description=f'MUST be "{VrsType.DERIVATIVE_MOL.value}".',
838846
)
839847
components: list[
@@ -844,7 +852,7 @@ class DerivativeMolecule(_VariationBase, BaseModelForbidExtra):
844852
min_length=2,
845853
)
846854
circular: bool | None = Field(
847-
None,
855+
default=None,
848856
description="A boolean indicating whether the molecule represented by the sequence is circular (true) or linear (false).",
849857
)
850858

@@ -864,7 +872,8 @@ class CopyNumberCount(_VariationBase, BaseModelForbidExtra):
864872
"""
865873

866874
type: Literal["CopyNumberCount"] = Field(
867-
VrsType.CN_COUNT.value, description=f'MUST be "{VrsType.CN_COUNT.value}"'
875+
default=VrsType.CN_COUNT.value,
876+
description=f'MUST be "{VrsType.CN_COUNT.value}"',
868877
)
869878
location: iriReference | SequenceLocation = Field(
870879
...,
@@ -887,7 +896,8 @@ class CopyNumberChange(_VariationBase, BaseModelForbidExtra):
887896
model_config = ConfigDict(use_enum_values=True)
888897

889898
type: Literal["CopyNumberChange"] = Field(
890-
VrsType.CN_CHANGE.value, description=f'MUST be "{VrsType.CN_CHANGE.value}"'
899+
default=VrsType.CN_CHANGE.value,
900+
description=f'MUST be "{VrsType.CN_CHANGE.value}"',
891901
)
892902
location: iriReference | SequenceLocation = Field(
893903
...,

0 commit comments

Comments
 (0)