diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/a_model.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/a_model.py index 2bf3e140d..25bceb17c 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/a_model.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/a_model.py @@ -1,5 +1,5 @@ import datetime -from typing import Any, Dict, List, Optional, Union, cast +from typing import Any, Dict, List, Optional, Type, TypeVar, Union, cast import attr from dateutil.parser import isoparse @@ -8,6 +8,8 @@ from ..models.different_enum import DifferentEnum from ..types import UNSET, Unset +T = TypeVar("T", bound="AModel") + @attr.s(auto_attribs=True) class AModel: @@ -75,8 +77,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "AModel": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() an_enum_value = AnEnum(d.pop("an_enum_value")) @@ -124,7 +126,7 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat not_required_not_nullable = d.pop("not_required_not_nullable", UNSET) - a_model = AModel( + a_model = cls( an_enum_value=an_enum_value, a_camel_date_time=a_camel_date_time, a_date=a_date, diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/body_upload_file_tests_upload_post.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/body_upload_file_tests_upload_post.py index 657411d54..97db03356 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/body_upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/body_upload_file_tests_upload_post.py @@ -1,10 +1,12 @@ from io import BytesIO -from typing import Any, Dict +from typing import Any, Dict, Type, TypeVar import attr from ..types import File +T = TypeVar("T", bound="BodyUploadFileTestsUploadPost") + @attr.s(auto_attribs=True) class BodyUploadFileTestsUploadPost: @@ -24,12 +26,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "BodyUploadFileTestsUploadPost": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() some_file = File(payload=BytesIO(d.pop("some_file"))) - body_upload_file_tests_upload_post = BodyUploadFileTestsUploadPost( + body_upload_file_tests_upload_post = cls( some_file=some_file, ) diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/free_form_model.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/free_form_model.py index 0e1b93899..1a86b6bac 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/free_form_model.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/free_form_model.py @@ -1,7 +1,9 @@ -from typing import Any, Dict, List +from typing import Any, Dict, List, Type, TypeVar import attr +T = TypeVar("T", bound="FreeFormModel") + @attr.s(auto_attribs=True) class FreeFormModel: @@ -17,10 +19,10 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "FreeFormModel": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - free_form_model = FreeFormModel() + free_form_model = cls() free_form_model.additional_properties = d return free_form_model diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/http_validation_error.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/http_validation_error.py index 1b25a6d98..3025b07af 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/http_validation_error.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/http_validation_error.py @@ -1,10 +1,12 @@ -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Type, TypeVar, Union import attr from ..models.validation_error import ValidationError from ..types import UNSET, Unset +T = TypeVar("T", bound="HTTPValidationError") + @attr.s(auto_attribs=True) class HTTPValidationError: @@ -28,8 +30,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "HTTPValidationError": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() detail = [] _detail = d.pop("detail", UNSET) @@ -38,7 +40,7 @@ def from_dict(src_dict: Dict[str, Any]) -> "HTTPValidationError": detail.append(detail_item) - http_validation_error = HTTPValidationError( + http_validation_error = cls( detail=detail, ) diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_additional_properties_inlined.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_additional_properties_inlined.py index 30acb7957..a81e57a8e 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_additional_properties_inlined.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_additional_properties_inlined.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Type, TypeVar, Union import attr @@ -7,6 +7,8 @@ ) from ..types import UNSET, Unset +T = TypeVar("T", bound="ModelWithAdditionalPropertiesInlined") + @attr.s(auto_attribs=True) class ModelWithAdditionalPropertiesInlined: @@ -30,12 +32,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithAdditionalPropertiesInlined": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() a_number = d.pop("a_number", UNSET) - model_with_additional_properties_inlined = ModelWithAdditionalPropertiesInlined( + model_with_additional_properties_inlined = cls( a_number=a_number, ) diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_additional_properties_inlined_additional_property.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_additional_properties_inlined_additional_property.py index 4ce45f8ef..baedb6193 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_additional_properties_inlined_additional_property.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_additional_properties_inlined_additional_property.py @@ -1,9 +1,11 @@ -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Type, TypeVar, Union import attr from ..types import UNSET, Unset +T = TypeVar("T", bound="ModelWithAdditionalPropertiesInlinedAdditionalProperty") + @attr.s(auto_attribs=True) class ModelWithAdditionalPropertiesInlinedAdditionalProperty: @@ -23,15 +25,13 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithAdditionalPropertiesInlinedAdditionalProperty": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() extra_props_prop = d.pop("extra_props_prop", UNSET) - model_with_additional_properties_inlined_additional_property = ( - ModelWithAdditionalPropertiesInlinedAdditionalProperty( - extra_props_prop=extra_props_prop, - ) + model_with_additional_properties_inlined_additional_property = cls( + extra_props_prop=extra_props_prop, ) model_with_additional_properties_inlined_additional_property.additional_properties = d diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_additional_properties_refed.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_additional_properties_refed.py index c5eb4a7a4..b265db582 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_additional_properties_refed.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_additional_properties_refed.py @@ -1,9 +1,11 @@ -from typing import Any, Dict, List +from typing import Any, Dict, List, Type, TypeVar import attr from ..models.an_enum import AnEnum +T = TypeVar("T", bound="ModelWithAdditionalPropertiesRefed") + @attr.s(auto_attribs=True) class ModelWithAdditionalPropertiesRefed: @@ -21,10 +23,10 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithAdditionalPropertiesRefed": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - model_with_additional_properties_refed = ModelWithAdditionalPropertiesRefed() + model_with_additional_properties_refed = cls() additional_properties = {} for prop_name, prop_dict in d.items(): diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_any_json_properties.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_any_json_properties.py index 62481f913..7696b9753 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_any_json_properties.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_any_json_properties.py @@ -1,10 +1,12 @@ -from typing import Any, Dict, List, Union, cast +from typing import Any, Dict, List, Type, TypeVar, Union, cast import attr from ..models.model_with_any_json_properties_additional_property import ModelWithAnyJsonPropertiesAdditionalProperty from ..types import Unset +T = TypeVar("T", bound="ModelWithAnyJsonProperties") + @attr.s(auto_attribs=True) class ModelWithAnyJsonProperties: @@ -31,10 +33,10 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithAnyJsonProperties": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - model_with_any_json_properties = ModelWithAnyJsonProperties() + model_with_any_json_properties = cls() additional_properties = {} for prop_name, prop_dict in d.items(): diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_any_json_properties_additional_property.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_any_json_properties_additional_property.py index c823a73ed..69aa84641 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_any_json_properties_additional_property.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_any_json_properties_additional_property.py @@ -1,7 +1,9 @@ -from typing import Any, Dict, List +from typing import Any, Dict, List, Type, TypeVar import attr +T = TypeVar("T", bound="ModelWithAnyJsonPropertiesAdditionalProperty") + @attr.s(auto_attribs=True) class ModelWithAnyJsonPropertiesAdditionalProperty: @@ -17,10 +19,10 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithAnyJsonPropertiesAdditionalProperty": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - model_with_any_json_properties_additional_property = ModelWithAnyJsonPropertiesAdditionalProperty() + model_with_any_json_properties_additional_property = cls() model_with_any_json_properties_additional_property.additional_properties = d return model_with_any_json_properties_additional_property diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_primitive_additional_properties.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_primitive_additional_properties.py index 47d65d90b..a45edaab8 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_primitive_additional_properties.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_primitive_additional_properties.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Union, cast +from typing import Any, Dict, List, Type, TypeVar, Union, cast import attr @@ -7,6 +7,8 @@ ) from ..types import UNSET, Unset +T = TypeVar("T", bound="ModelWithPrimitiveAdditionalProperties") + @attr.s(auto_attribs=True) class ModelWithPrimitiveAdditionalProperties: @@ -28,8 +30,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithPrimitiveAdditionalProperties": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() a_date_holder: Union[ModelWithPrimitiveAdditionalPropertiesADateHolder, Unset] = UNSET _a_date_holder = d.pop("a_date_holder", UNSET) @@ -38,7 +40,7 @@ def from_dict(src_dict: Dict[str, Any]) -> "ModelWithPrimitiveAdditionalProperti cast(Dict[str, Any], _a_date_holder) ) - model_with_primitive_additional_properties = ModelWithPrimitiveAdditionalProperties( + model_with_primitive_additional_properties = cls( a_date_holder=a_date_holder, ) diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_primitive_additional_properties_a_date_holder.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_primitive_additional_properties_a_date_holder.py index 394c68a12..3df34635f 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_primitive_additional_properties_a_date_holder.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_primitive_additional_properties_a_date_holder.py @@ -1,9 +1,11 @@ import datetime -from typing import Any, Dict, List +from typing import Any, Dict, List, Type, TypeVar import attr from dateutil.parser import isoparse +T = TypeVar("T", bound="ModelWithPrimitiveAdditionalPropertiesADateHolder") + @attr.s(auto_attribs=True) class ModelWithPrimitiveAdditionalPropertiesADateHolder: @@ -21,10 +23,10 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithPrimitiveAdditionalPropertiesADateHolder": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - model_with_primitive_additional_properties_a_date_holder = ModelWithPrimitiveAdditionalPropertiesADateHolder() + model_with_primitive_additional_properties_a_date_holder = cls() additional_properties = {} for prop_name, prop_dict in d.items(): diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_union_property.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_union_property.py index cbecc7c90..960360cdb 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_union_property.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_union_property.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, Union +from typing import Any, Dict, Type, TypeVar, Union import attr @@ -6,6 +6,8 @@ from ..models.an_int_enum import AnIntEnum from ..types import UNSET, Unset +T = TypeVar("T", bound="ModelWithUnionProperty") + @attr.s(auto_attribs=True) class ModelWithUnionProperty: @@ -34,8 +36,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithUnionProperty": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]: @@ -59,7 +61,7 @@ def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]: a_property = _parse_a_property(d.pop("a_property", UNSET)) - model_with_union_property = ModelWithUnionProperty( + model_with_union_property = cls( a_property=a_property, ) diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/test_inline_objects_json_body.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/test_inline_objects_json_body.py index e607209ca..1ee542873 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/test_inline_objects_json_body.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/test_inline_objects_json_body.py @@ -1,9 +1,11 @@ -from typing import Any, Dict, Union +from typing import Any, Dict, Type, TypeVar, Union import attr from ..types import UNSET, Unset +T = TypeVar("T", bound="TestInlineObjectsJsonBody") + @attr.s(auto_attribs=True) class TestInlineObjectsJsonBody: @@ -21,12 +23,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "TestInlineObjectsJsonBody": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() a_property = d.pop("a_property", UNSET) - test_inline_objects_json_body = TestInlineObjectsJsonBody( + test_inline_objects_json_body = cls( a_property=a_property, ) diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/test_inline_objects_response_200.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/test_inline_objects_response_200.py index 79daf6731..6e44a5b14 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/test_inline_objects_response_200.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/test_inline_objects_response_200.py @@ -1,9 +1,11 @@ -from typing import Any, Dict, Union +from typing import Any, Dict, Type, TypeVar, Union import attr from ..types import UNSET, Unset +T = TypeVar("T", bound="TestInlineObjectsResponse_200") + @attr.s(auto_attribs=True) class TestInlineObjectsResponse_200: @@ -21,12 +23,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "TestInlineObjectsResponse_200": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() a_property = d.pop("a_property", UNSET) - test_inline_objects_response_200 = TestInlineObjectsResponse_200( + test_inline_objects_response_200 = cls( a_property=a_property, ) diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/validation_error.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/validation_error.py index 2cd2b8959..a0cd07b51 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/validation_error.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/validation_error.py @@ -1,7 +1,9 @@ -from typing import Any, Dict, List, cast +from typing import Any, Dict, List, Type, TypeVar, cast import attr +T = TypeVar("T", bound="ValidationError") + @attr.s(auto_attribs=True) class ValidationError: @@ -28,8 +30,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ValidationError": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() loc = cast(List[str], d.pop("loc")) @@ -37,7 +39,7 @@ def from_dict(src_dict: Dict[str, Any]) -> "ValidationError": type = d.pop("type") - validation_error = ValidationError( + validation_error = cls( loc=loc, msg=msg, type=type, diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py index 2bf3e140d..25bceb17c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py @@ -1,5 +1,5 @@ import datetime -from typing import Any, Dict, List, Optional, Union, cast +from typing import Any, Dict, List, Optional, Type, TypeVar, Union, cast import attr from dateutil.parser import isoparse @@ -8,6 +8,8 @@ from ..models.different_enum import DifferentEnum from ..types import UNSET, Unset +T = TypeVar("T", bound="AModel") + @attr.s(auto_attribs=True) class AModel: @@ -75,8 +77,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "AModel": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() an_enum_value = AnEnum(d.pop("an_enum_value")) @@ -124,7 +126,7 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat not_required_not_nullable = d.pop("not_required_not_nullable", UNSET) - a_model = AModel( + a_model = cls( an_enum_value=an_enum_value, a_camel_date_time=a_camel_date_time, a_date=a_date, diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py index 657411d54..97db03356 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py @@ -1,10 +1,12 @@ from io import BytesIO -from typing import Any, Dict +from typing import Any, Dict, Type, TypeVar import attr from ..types import File +T = TypeVar("T", bound="BodyUploadFileTestsUploadPost") + @attr.s(auto_attribs=True) class BodyUploadFileTestsUploadPost: @@ -24,12 +26,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "BodyUploadFileTestsUploadPost": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() some_file = File(payload=BytesIO(d.pop("some_file"))) - body_upload_file_tests_upload_post = BodyUploadFileTestsUploadPost( + body_upload_file_tests_upload_post = cls( some_file=some_file, ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py index 0e1b93899..1a86b6bac 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py @@ -1,7 +1,9 @@ -from typing import Any, Dict, List +from typing import Any, Dict, List, Type, TypeVar import attr +T = TypeVar("T", bound="FreeFormModel") + @attr.s(auto_attribs=True) class FreeFormModel: @@ -17,10 +19,10 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "FreeFormModel": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - free_form_model = FreeFormModel() + free_form_model = cls() free_form_model.additional_properties = d return free_form_model diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py b/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py index 1b25a6d98..3025b07af 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py @@ -1,10 +1,12 @@ -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Type, TypeVar, Union import attr from ..models.validation_error import ValidationError from ..types import UNSET, Unset +T = TypeVar("T", bound="HTTPValidationError") + @attr.s(auto_attribs=True) class HTTPValidationError: @@ -28,8 +30,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "HTTPValidationError": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() detail = [] _detail = d.pop("detail", UNSET) @@ -38,7 +40,7 @@ def from_dict(src_dict: Dict[str, Any]) -> "HTTPValidationError": detail.append(detail_item) - http_validation_error = HTTPValidationError( + http_validation_error = cls( detail=detail, ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py index 30acb7957..a81e57a8e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Type, TypeVar, Union import attr @@ -7,6 +7,8 @@ ) from ..types import UNSET, Unset +T = TypeVar("T", bound="ModelWithAdditionalPropertiesInlined") + @attr.s(auto_attribs=True) class ModelWithAdditionalPropertiesInlined: @@ -30,12 +32,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithAdditionalPropertiesInlined": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() a_number = d.pop("a_number", UNSET) - model_with_additional_properties_inlined = ModelWithAdditionalPropertiesInlined( + model_with_additional_properties_inlined = cls( a_number=a_number, ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py index 4ce45f8ef..baedb6193 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py @@ -1,9 +1,11 @@ -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Type, TypeVar, Union import attr from ..types import UNSET, Unset +T = TypeVar("T", bound="ModelWithAdditionalPropertiesInlinedAdditionalProperty") + @attr.s(auto_attribs=True) class ModelWithAdditionalPropertiesInlinedAdditionalProperty: @@ -23,15 +25,13 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithAdditionalPropertiesInlinedAdditionalProperty": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() extra_props_prop = d.pop("extra_props_prop", UNSET) - model_with_additional_properties_inlined_additional_property = ( - ModelWithAdditionalPropertiesInlinedAdditionalProperty( - extra_props_prop=extra_props_prop, - ) + model_with_additional_properties_inlined_additional_property = cls( + extra_props_prop=extra_props_prop, ) model_with_additional_properties_inlined_additional_property.additional_properties = d diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py index c5eb4a7a4..b265db582 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py @@ -1,9 +1,11 @@ -from typing import Any, Dict, List +from typing import Any, Dict, List, Type, TypeVar import attr from ..models.an_enum import AnEnum +T = TypeVar("T", bound="ModelWithAdditionalPropertiesRefed") + @attr.s(auto_attribs=True) class ModelWithAdditionalPropertiesRefed: @@ -21,10 +23,10 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithAdditionalPropertiesRefed": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - model_with_additional_properties_refed = ModelWithAdditionalPropertiesRefed() + model_with_additional_properties_refed = cls() additional_properties = {} for prop_name, prop_dict in d.items(): diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py index 62481f913..7696b9753 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py @@ -1,10 +1,12 @@ -from typing import Any, Dict, List, Union, cast +from typing import Any, Dict, List, Type, TypeVar, Union, cast import attr from ..models.model_with_any_json_properties_additional_property import ModelWithAnyJsonPropertiesAdditionalProperty from ..types import Unset +T = TypeVar("T", bound="ModelWithAnyJsonProperties") + @attr.s(auto_attribs=True) class ModelWithAnyJsonProperties: @@ -31,10 +33,10 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithAnyJsonProperties": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - model_with_any_json_properties = ModelWithAnyJsonProperties() + model_with_any_json_properties = cls() additional_properties = {} for prop_name, prop_dict in d.items(): diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property.py index c823a73ed..69aa84641 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property.py @@ -1,7 +1,9 @@ -from typing import Any, Dict, List +from typing import Any, Dict, List, Type, TypeVar import attr +T = TypeVar("T", bound="ModelWithAnyJsonPropertiesAdditionalProperty") + @attr.s(auto_attribs=True) class ModelWithAnyJsonPropertiesAdditionalProperty: @@ -17,10 +19,10 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithAnyJsonPropertiesAdditionalProperty": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - model_with_any_json_properties_additional_property = ModelWithAnyJsonPropertiesAdditionalProperty() + model_with_any_json_properties_additional_property = cls() model_with_any_json_properties_additional_property.additional_properties = d return model_with_any_json_properties_additional_property diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py index 47d65d90b..a45edaab8 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Union, cast +from typing import Any, Dict, List, Type, TypeVar, Union, cast import attr @@ -7,6 +7,8 @@ ) from ..types import UNSET, Unset +T = TypeVar("T", bound="ModelWithPrimitiveAdditionalProperties") + @attr.s(auto_attribs=True) class ModelWithPrimitiveAdditionalProperties: @@ -28,8 +30,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithPrimitiveAdditionalProperties": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() a_date_holder: Union[ModelWithPrimitiveAdditionalPropertiesADateHolder, Unset] = UNSET _a_date_holder = d.pop("a_date_holder", UNSET) @@ -38,7 +40,7 @@ def from_dict(src_dict: Dict[str, Any]) -> "ModelWithPrimitiveAdditionalProperti cast(Dict[str, Any], _a_date_holder) ) - model_with_primitive_additional_properties = ModelWithPrimitiveAdditionalProperties( + model_with_primitive_additional_properties = cls( a_date_holder=a_date_holder, ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py index 394c68a12..3df34635f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py @@ -1,9 +1,11 @@ import datetime -from typing import Any, Dict, List +from typing import Any, Dict, List, Type, TypeVar import attr from dateutil.parser import isoparse +T = TypeVar("T", bound="ModelWithPrimitiveAdditionalPropertiesADateHolder") + @attr.s(auto_attribs=True) class ModelWithPrimitiveAdditionalPropertiesADateHolder: @@ -21,10 +23,10 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithPrimitiveAdditionalPropertiesADateHolder": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - model_with_primitive_additional_properties_a_date_holder = ModelWithPrimitiveAdditionalPropertiesADateHolder() + model_with_primitive_additional_properties_a_date_holder = cls() additional_properties = {} for prop_name, prop_dict in d.items(): diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py index cbecc7c90..960360cdb 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, Union +from typing import Any, Dict, Type, TypeVar, Union import attr @@ -6,6 +6,8 @@ from ..models.an_int_enum import AnIntEnum from ..types import UNSET, Unset +T = TypeVar("T", bound="ModelWithUnionProperty") + @attr.s(auto_attribs=True) class ModelWithUnionProperty: @@ -34,8 +36,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ModelWithUnionProperty": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]: @@ -59,7 +61,7 @@ def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]: a_property = _parse_a_property(d.pop("a_property", UNSET)) - model_with_union_property = ModelWithUnionProperty( + model_with_union_property = cls( a_property=a_property, ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py index e607209ca..1ee542873 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py @@ -1,9 +1,11 @@ -from typing import Any, Dict, Union +from typing import Any, Dict, Type, TypeVar, Union import attr from ..types import UNSET, Unset +T = TypeVar("T", bound="TestInlineObjectsJsonBody") + @attr.s(auto_attribs=True) class TestInlineObjectsJsonBody: @@ -21,12 +23,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "TestInlineObjectsJsonBody": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() a_property = d.pop("a_property", UNSET) - test_inline_objects_json_body = TestInlineObjectsJsonBody( + test_inline_objects_json_body = cls( a_property=a_property, ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py index 79daf6731..6e44a5b14 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py @@ -1,9 +1,11 @@ -from typing import Any, Dict, Union +from typing import Any, Dict, Type, TypeVar, Union import attr from ..types import UNSET, Unset +T = TypeVar("T", bound="TestInlineObjectsResponse_200") + @attr.s(auto_attribs=True) class TestInlineObjectsResponse_200: @@ -21,12 +23,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "TestInlineObjectsResponse_200": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() a_property = d.pop("a_property", UNSET) - test_inline_objects_response_200 = TestInlineObjectsResponse_200( + test_inline_objects_response_200 = cls( a_property=a_property, ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py b/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py index 2cd2b8959..a0cd07b51 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py @@ -1,7 +1,9 @@ -from typing import Any, Dict, List, cast +from typing import Any, Dict, List, Type, TypeVar, cast import attr +T = TypeVar("T", bound="ValidationError") + @attr.s(auto_attribs=True) class ValidationError: @@ -28,8 +30,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "ValidationError": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() loc = cast(List[str], d.pop("loc")) @@ -37,7 +39,7 @@ def from_dict(src_dict: Dict[str, Any]) -> "ValidationError": type = d.pop("type") - validation_error = ValidationError( + validation_error = cls( loc=loc, msg=msg, type=type, diff --git a/openapi_python_client/templates/model.pyi b/openapi_python_client/templates/model.pyi index 0c81a32f9..147c1e7f5 100644 --- a/openapi_python_client/templates/model.pyi +++ b/openapi_python_client/templates/model.pyi @@ -1,4 +1,4 @@ -from typing import Any, Dict +from typing import Any, Dict, Type, TypeVar {% if model.additional_properties %} from typing import List @@ -18,6 +18,8 @@ from ..types import UNSET, Unset {% set additional_property_type = 'Any' if model.additional_properties == True else model.additional_properties.get_type_string() %} {% endif %} +T = TypeVar("T", bound="{{ model.reference.class_name }}") + @attr.s(auto_attribs=True) class {{ model.reference.class_name }}: """ {{ model.description }} """ @@ -72,8 +74,8 @@ class {{ model.reference.class_name }}: return field_dict - @staticmethod - def from_dict(src_dict: Dict[str, Any]) -> "{{ model.reference.class_name }}": + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() {% for property in model.required_properties + model.optional_properties %} {% if property.required %} @@ -89,7 +91,7 @@ class {{ model.reference.class_name }}: {% endif %} {% endfor %} - {{model.reference.module_name}} = {{ model.reference.class_name }}( + {{model.reference.module_name}} = cls( {% for property in model.required_properties + model.optional_properties %} {{ property.python_name }}={{ property.python_name }}, {% endfor %} diff --git a/pyproject.toml b/pyproject.toml index 222b69561..2d58c08ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "openapi-python-client" -version = "0.7.3" +version = "0.7.4" description = "Generate modern Python clients from OpenAPI" repository = "https://github.com/triaxtec/openapi-python-client" license = "MIT"