Skip to content

feat: Allow any Mapping in generated from_dict functions #1211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -43,8 +44,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
prop_with_no_desc = d.pop("propWithNoDesc", UNSET)

prop_with_desc = d.pop("propWithDesc", UNSET)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -31,8 +32,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
prop_with_no_desc = d.pop("propWithNoDesc", UNSET)

prop_with_desc = d.pop("propWithDesc", UNSET)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -30,8 +31,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
model_type = d.pop("modelType", UNSET)

a_discriminated_union_type_1 = cls(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -30,8 +31,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
model_type = d.pop("modelType", UNSET)

a_discriminated_union_type_2 = cls(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -38,8 +39,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
an_required_field = d.pop("an_required_field")

an_optional_field = d.pop("an_optional_field", UNSET)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, Union, cast
from uuid import UUID

Expand Down Expand Up @@ -252,11 +253,11 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.free_form_model import FreeFormModel
from ..models.model_with_union_property import ModelWithUnionProperty

d = src_dict.copy()
d = dict(src_dict)
an_enum_value = AnEnum(d.pop("an_enum_value"))

an_allof_enum_with_overridden_default = AnAllOfEnum(d.pop("an_allof_enum_with_overridden_default"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from collections.abc import Mapping
from io import BytesIO
from typing import Any, TypeVar, cast

Expand Down Expand Up @@ -213,8 +214,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
enum_properties_ref = []
_enum_properties_ref = d.pop("enum_properties_ref")
for componentsschemas_an_other_array_of_enum_item_data in _enum_properties_ref:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -45,8 +46,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
a_sub_property = d.pop("a_sub_property", UNSET)

type_ = d.pop("type", UNSET)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -45,8 +46,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
a_sub_property = d.pop("a_sub_property", UNSET)

type_ = d.pop("type", UNSET)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -41,12 +42,12 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.an_array_with_a_circular_ref_in_items_object_b_item import (
AnArrayWithACircularRefInItemsObjectBItem,
)

d = src_dict.copy()
d = dict(src_dict)
circular = []
_circular = d.pop("circular", UNSET)
for componentsschemas_an_array_with_a_circular_ref_in_items_object_b_item_data in _circular or []:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar

from attrs import define as _attrs_define
Expand Down Expand Up @@ -35,12 +36,12 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.an_array_with_a_circular_ref_in_items_object_additional_properties_b_item import (
AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem,
)

d = src_dict.copy()
d = dict(src_dict)
an_array_with_a_circular_ref_in_items_object_additional_properties_a_item = cls()

additional_properties = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar

from attrs import define as _attrs_define
Expand Down Expand Up @@ -35,12 +36,12 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.an_array_with_a_circular_ref_in_items_object_additional_properties_a_item import (
AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem,
)

d = src_dict.copy()
d = dict(src_dict)
an_array_with_a_circular_ref_in_items_object_additional_properties_b_item = cls()

additional_properties = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -41,12 +42,12 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.an_array_with_a_circular_ref_in_items_object_a_item import (
AnArrayWithACircularRefInItemsObjectAItem,
)

d = src_dict.copy()
d = dict(src_dict)
circular = []
_circular = d.pop("circular", UNSET)
for componentsschemas_an_array_with_a_circular_ref_in_items_object_a_item_data in _circular or []:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar

from attrs import define as _attrs_define
Expand Down Expand Up @@ -27,8 +28,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
an_array_with_a_recursive_ref_in_items_object_additional_properties_item = cls()

additional_properties = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -37,8 +38,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
recursive = []
_recursive = d.pop("recursive", UNSET)
for componentsschemas_an_array_with_a_recursive_ref_in_items_object_item_data in _recursive or []:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -48,8 +49,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
another_sub_property = d.pop("another_sub_property", UNSET)

_type_ = d.pop("type", UNSET)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import json
from collections.abc import Mapping
from io import BytesIO
from typing import TYPE_CHECKING, Any, TypeVar, Union, cast

Expand Down Expand Up @@ -278,7 +279,7 @@ def to_multipart(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.a_form_data import AFormData
from ..models.body_upload_file_tests_upload_post_additional_property import (
BodyUploadFileTestsUploadPostAdditionalProperty,
Expand All @@ -291,7 +292,7 @@ def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
BodyUploadFileTestsUploadPostSomeOptionalObject,
)

d = src_dict.copy()
d = dict(src_dict)
some_file = File(payload=BytesIO(d.pop("some_file")))

some_required_number = d.pop("some_required_number")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -30,8 +31,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
foo = d.pop("foo", UNSET)

body_upload_file_tests_upload_post_additional_property = cls(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar, Union

from attrs import define as _attrs_define
Expand Down Expand Up @@ -30,8 +31,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
bar = d.pop("bar", UNSET)

body_upload_file_tests_upload_post_some_nullable_object = cls(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar

from attrs import define as _attrs_define
Expand Down Expand Up @@ -35,8 +36,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
num = d.pop("num")

text = d.pop("text")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Mapping
from typing import Any, TypeVar

from attrs import define as _attrs_define
Expand Down Expand Up @@ -30,8 +31,8 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
d = src_dict.copy()
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
foo = d.pop("foo")

body_upload_file_tests_upload_post_some_optional_object = cls(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, Union, cast
from uuid import UUID

Expand Down Expand Up @@ -260,11 +261,11 @@ def to_dict(self) -> dict[str, Any]:
return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.free_form_model import FreeFormModel
from ..models.model_with_union_property import ModelWithUnionProperty

d = src_dict.copy()
d = dict(src_dict)
an_enum_value = AnEnum(d.pop("an_enum_value"))

an_allof_enum_with_overridden_default = AnAllOfEnum(d.pop("an_allof_enum_with_overridden_default"))
Expand Down
Loading