Skip to content

Commit cf35a2b

Browse files
authored
Merge pull request #759 from cordada/task/add-typing-self-annotations
Annotate method return types with `typing.Self` where appropriate
2 parents c812fa7 + c89f7e0 commit cf35a2b

7 files changed

+19
-12
lines changed

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies = [
2727
"pyOpenSSL>=24.0.0",
2828
"pytz>=2019.3",
2929
"signxml>=4.0.0",
30+
"typing-extensions>=4.0.1",
3031
]
3132
requires-python = ">=3.8, <3.11"
3233
authors = [

requirements.in

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ pydantic==2.10.4
1919
pyOpenSSL==24.3.0
2020
pytz==2024.2
2121
signxml==4.0.3
22+
typing-extensions==4.12.2

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ sqlparse==0.5.0
8181
# via django
8282
typing-extensions==4.12.2
8383
# via
84+
# -r requirements.in
8485
# annotated-types
8586
# asgiref
8687
# pydantic

src/cl_sii/dte/data_models.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from typing import Mapping, Optional, Sequence
2525

2626
import pydantic
27+
from typing_extensions import Self
2728

2829
import cl_sii.contribuyente.constants
2930
import cl_sii.rut.constants
@@ -854,7 +855,7 @@ def validate_referencias_numero_linea_ref_order(cls, v: object) -> object:
854855
@pydantic.model_validator(mode='after')
855856
def validate_referencias_rut_otro_is_consistent_with_tipo_dte(
856857
self, info: pydantic.ValidationInfo
857-
) -> DteXmlData:
858+
) -> Self:
858859
referencias = self.referencias
859860
tipo_dte = self.tipo_dte
860861

@@ -880,7 +881,7 @@ def validate_referencias_rut_otro_is_consistent_with_tipo_dte(
880881
@pydantic.model_validator(mode='after')
881882
def validate_referencias_rut_otro_is_consistent_with_emisor_rut(
882883
self, info: pydantic.ValidationInfo
883-
) -> DteXmlData:
884+
) -> Self:
884885
referencias = self.referencias
885886
emisor_rut = self.emisor_rut
886887

@@ -900,7 +901,7 @@ def validate_referencias_rut_otro_is_consistent_with_emisor_rut(
900901
return self
901902

902903
@pydantic.model_validator(mode='after')
903-
def validate_referencias_codigo_ref_is_consistent_with_tipo_dte(self) -> DteXmlData:
904+
def validate_referencias_codigo_ref_is_consistent_with_tipo_dte(self) -> Self:
904905
referencias = self.referencias
905906
tipo_dte = self.tipo_dte
906907

src/cl_sii/rcv/data_models.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from typing import ClassVar, Optional
1313

1414
import pydantic
15+
from typing_extensions import Self
1516

1617
import cl_sii.dte.data_models
1718
from cl_sii.base.constants import SII_OFFICIAL_TZ
@@ -174,7 +175,7 @@ def validate_datetime_tz(cls, v: object) -> object:
174175
return v
175176

176177
@pydantic.model_validator(mode='after')
177-
def validate_rcv_kind_is_consistent_with_rc_estado_contable(self) -> RcvDetalleEntry:
178+
def validate_rcv_kind_is_consistent_with_rc_estado_contable(self) -> Self:
178179
rcv_kind = self.RCV_KIND
179180
rc_estado_contable = self.RC_ESTADO_CONTABLE
180181

src/cl_sii/rtc/data_models.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from typing import ClassVar, Mapping, Optional
2525

2626
import pydantic
27+
from typing_extensions import Self
2728

2829
from cl_sii.base.constants import SII_OFFICIAL_TZ
2930
from cl_sii.dte import data_models as dte_data_models
@@ -508,7 +509,7 @@ def validate_monto_cedido(cls, v: object) -> object:
508509
return v
509510

510511
@pydantic.model_validator(mode='after')
511-
def validate_monto_cedido_does_not_exceed_dte_monto_total(self) -> CesionL1:
512+
def validate_monto_cedido_does_not_exceed_dte_monto_total(self) -> Self:
512513
monto_cedido = self.monto_cedido
513514
dte_monto_total = self.dte_monto_total
514515

@@ -705,7 +706,7 @@ def validate_contribuyente_razon_social(cls, v: object) -> object:
705706
return v
706707

707708
@pydantic.model_validator(mode='after')
708-
def validate_dte_data_l2(self) -> CesionL2:
709+
def validate_dte_data_l2(self) -> Self:
709710
dte_key = self.dte_key
710711
try:
711712
# Note: Delegate some validation to 'dte_data_models.DteDataL2'.

src/cl_sii/rtc/data_models_aec.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import ClassVar, Mapping, Optional, Sequence, Tuple
1111

1212
import pydantic
13+
from typing_extensions import Self
1314

1415
from cl_sii.base.constants import SII_OFFICIAL_TZ
1516
from cl_sii.dte import data_models as dte_data_models
@@ -342,7 +343,7 @@ def validate_datetime_tz(cls, v: object) -> object:
342343
return v
343344

344345
@pydantic.model_validator(mode='after')
345-
def validate_fecha_cesion_dt_is_consistent_with_dte(self) -> CesionAecXml:
346+
def validate_fecha_cesion_dt_is_consistent_with_dte(self) -> Self:
346347
fecha_cesion_dt = self.fecha_cesion_dt
347348
dte = self.dte
348349

@@ -352,7 +353,7 @@ def validate_fecha_cesion_dt_is_consistent_with_dte(self) -> CesionAecXml:
352353
return self
353354

354355
@pydantic.model_validator(mode='after')
355-
def validate_monto_cesion_does_not_exceed_dte_monto_total(self) -> CesionAecXml:
356+
def validate_monto_cesion_does_not_exceed_dte_monto_total(self) -> Self:
356357
monto_cesion = self.monto_cesion
357358
dte = self.dte
358359

@@ -365,7 +366,7 @@ def validate_monto_cesion_does_not_exceed_dte_monto_total(self) -> CesionAecXml:
365366
return self
366367

367368
@pydantic.model_validator(mode='after')
368-
def validate_fecha_ultimo_vencimiento_is_consistent_with_dte(self) -> CesionAecXml:
369+
def validate_fecha_ultimo_vencimiento_is_consistent_with_dte(self) -> Self:
369370
fecha_ultimo_vencimiento = self.fecha_ultimo_vencimiento
370371
dte = self.dte
371372

@@ -732,7 +733,7 @@ def validate_cesiones_seq_order(cls, v: object) -> object:
732733
# return v
733734

734735
@pydantic.model_validator(mode='after')
735-
def validate_dte_matches_cesiones_dtes(self) -> AecXml:
736+
def validate_dte_matches_cesiones_dtes(self) -> Self:
736737
dte = self.dte
737738
cesiones = self.cesiones
738739

@@ -751,7 +752,7 @@ def validate_dte_matches_cesiones_dtes(self) -> AecXml:
751752
return self
752753

753754
@pydantic.model_validator(mode='after')
754-
def validate_last_cesion_matches_some_fields(self) -> AecXml:
755+
def validate_last_cesion_matches_some_fields(self) -> Self:
755756
field_validations: Sequence[Tuple[str, str]] = [
756757
# (AecXml field, CesionAecXml field):
757758
# Even though it seems reasonable to expect that the date in `fecha_firma_dt`
@@ -784,7 +785,7 @@ def validate_last_cesion_matches_some_fields(self) -> AecXml:
784785
@pydantic.model_validator(mode='after')
785786
def validate_signature_value_and_signature_x509_cert_der_may_only_be_none_together(
786787
self,
787-
) -> AecXml:
788+
) -> Self:
788789
signature_value = self.signature_value
789790
signature_x509_cert_der = self.signature_x509_cert_der
790791

0 commit comments

Comments
 (0)