|
21 | 21 | import sys |
22 | 22 | import codecs |
23 | 23 | from typing import ( |
24 | | - Dict, |
25 | 24 | Any, |
26 | 25 | cast, |
27 | 26 | Optional, |
|
31 | 30 | Mapping, |
32 | 31 | Callable, |
33 | 32 | MutableMapping, |
34 | | - List, |
35 | 33 | ) |
36 | 34 |
|
37 | 35 | try: |
@@ -229,12 +227,12 @@ class Model: |
229 | 227 | serialization and deserialization. |
230 | 228 | """ |
231 | 229 |
|
232 | | - _subtype_map: Dict[str, Dict[str, Any]] = {} |
233 | | - _attribute_map: Dict[str, Dict[str, Any]] = {} |
234 | | - _validation: Dict[str, Dict[str, Any]] = {} |
| 230 | + _subtype_map: dict[str, dict[str, Any]] = {} |
| 231 | + _attribute_map: dict[str, dict[str, Any]] = {} |
| 232 | + _validation: dict[str, dict[str, Any]] = {} |
235 | 233 |
|
236 | 234 | def __init__(self, **kwargs: Any) -> None: |
237 | | - self.additional_properties: Optional[Dict[str, Any]] = {} |
| 235 | + self.additional_properties: Optional[dict[str, Any]] = {} |
238 | 236 | for k in kwargs: # pylint: disable=consider-using-dict-items |
239 | 237 | if k not in self._attribute_map: |
240 | 238 | _LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__) |
@@ -311,7 +309,7 @@ def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON: |
311 | 309 | def as_dict( |
312 | 310 | self, |
313 | 311 | keep_readonly: bool = True, |
314 | | - key_transformer: Callable[[str, Dict[str, Any], Any], Any] = attribute_transformer, |
| 312 | + key_transformer: Callable[[str, dict[str, Any], Any], Any] = attribute_transformer, |
315 | 313 | **kwargs: Any |
316 | 314 | ) -> JSON: |
317 | 315 | """Return a dict that can be serialized using json.dump. |
@@ -380,7 +378,7 @@ def deserialize(cls, data: Any, content_type: Optional[str] = None) -> Self: |
380 | 378 | def from_dict( |
381 | 379 | cls, |
382 | 380 | data: Any, |
383 | | - key_extractors: Optional[Callable[[str, Dict[str, Any], Any], Any]] = None, |
| 381 | + key_extractors: Optional[Callable[[str, dict[str, Any], Any], Any]] = None, |
384 | 382 | content_type: Optional[str] = None, |
385 | 383 | ) -> Self: |
386 | 384 | """Parse a dict using given key extractor return a model. |
@@ -414,7 +412,7 @@ def _flatten_subtype(cls, key, objects): |
414 | 412 | return {} |
415 | 413 | result = dict(cls._subtype_map[key]) |
416 | 414 | for valuetype in cls._subtype_map[key].values(): |
417 | | - result.update(objects[valuetype]._flatten_subtype(key, objects)) # pylint: disable=protected-access |
| 415 | + result |= objects[valuetype]._flatten_subtype(key, objects) # pylint: disable=protected-access |
418 | 416 | return result |
419 | 417 |
|
420 | 418 | @classmethod |
@@ -528,7 +526,7 @@ def __init__(self, classes: Optional[Mapping[str, type]] = None) -> None: |
528 | 526 | "[]": self.serialize_iter, |
529 | 527 | "{}": self.serialize_dict, |
530 | 528 | } |
531 | | - self.dependencies: Dict[str, type] = dict(classes) if classes else {} |
| 529 | + self.dependencies: dict[str, type] = dict(classes) if classes else {} |
532 | 530 | self.key_transformer = full_restapi_key_transformer |
533 | 531 | self.client_side_validation = True |
534 | 532 |
|
@@ -579,7 +577,7 @@ def _serialize( # pylint: disable=too-many-nested-blocks, too-many-branches, to |
579 | 577 |
|
580 | 578 | if attr_name == "additional_properties" and attr_desc["key"] == "": |
581 | 579 | if target_obj.additional_properties is not None: |
582 | | - serialized.update(target_obj.additional_properties) |
| 580 | + serialized |= target_obj.additional_properties |
583 | 581 | continue |
584 | 582 | try: |
585 | 583 |
|
@@ -1184,7 +1182,7 @@ def rest_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argumen |
1184 | 1182 |
|
1185 | 1183 | while "." in key: |
1186 | 1184 | # Need the cast, as for some reasons "split" is typed as list[str | Any] |
1187 | | - dict_keys = cast(List[str], _FLATTEN.split(key)) |
| 1185 | + dict_keys = cast(list[str], _FLATTEN.split(key)) |
1188 | 1186 | if len(dict_keys) == 1: |
1189 | 1187 | key = _decode_attribute_map_key(dict_keys[0]) |
1190 | 1188 | break |
@@ -1386,7 +1384,7 @@ def __init__(self, classes: Optional[Mapping[str, type]] = None) -> None: |
1386 | 1384 | "duration": (isodate.Duration, datetime.timedelta), |
1387 | 1385 | "iso-8601": (datetime.datetime), |
1388 | 1386 | } |
1389 | | - self.dependencies: Dict[str, type] = dict(classes) if classes else {} |
| 1387 | + self.dependencies: dict[str, type] = dict(classes) if classes else {} |
1390 | 1388 | self.key_extractors = [rest_key_extractor, xml_key_extractor] |
1391 | 1389 | # Additional properties only works if the "rest_key_extractor" is used to |
1392 | 1390 | # extract the keys. Making it to work whatever the key extractor is too much |
|
0 commit comments