updates
This commit is contained in:
@@ -3,7 +3,7 @@ from __future__ import annotations as _annotations
|
||||
import typing
|
||||
from copy import deepcopy
|
||||
from enum import Enum
|
||||
from typing import Any, Tuple
|
||||
from typing import Any
|
||||
|
||||
import typing_extensions
|
||||
|
||||
@@ -18,7 +18,7 @@ if typing.TYPE_CHECKING:
|
||||
from .._internal._utils import AbstractSetIntStr, MappingIntStrAny
|
||||
|
||||
AnyClassMethod = classmethod[Any, Any, Any]
|
||||
TupleGenerator = typing.Generator[Tuple[str, Any], None, None]
|
||||
TupleGenerator = typing.Generator[tuple[str, Any], None, None]
|
||||
Model = typing.TypeVar('Model', bound='BaseModel')
|
||||
# should be `set[int] | set[str] | dict[int, IncEx] | dict[str, IncEx] | None`, but mypy can't cope
|
||||
IncEx: typing_extensions.TypeAlias = 'set[int] | set[str] | dict[int, Any] | dict[str, Any] | None'
|
||||
@@ -40,11 +40,11 @@ def _iter(
|
||||
# The extra "is not None" guards are not logically necessary but optimizes performance for the simple case.
|
||||
if exclude is not None:
|
||||
exclude = _utils.ValueItems.merge(
|
||||
{k: v.exclude for k, v in self.model_fields.items() if v.exclude is not None}, exclude
|
||||
{k: v.exclude for k, v in self.__pydantic_fields__.items() if v.exclude is not None}, exclude
|
||||
)
|
||||
|
||||
if include is not None:
|
||||
include = _utils.ValueItems.merge({k: True for k in self.model_fields}, include, intersect=True)
|
||||
include = _utils.ValueItems.merge(dict.fromkeys(self.__pydantic_fields__, True), include, intersect=True)
|
||||
|
||||
allowed_keys = _calculate_keys(self, include=include, exclude=exclude, exclude_unset=exclude_unset) # type: ignore
|
||||
if allowed_keys is None and not (to_dict or by_alias or exclude_unset or exclude_defaults or exclude_none):
|
||||
@@ -68,15 +68,15 @@ def _iter(
|
||||
|
||||
if exclude_defaults:
|
||||
try:
|
||||
field = self.model_fields[field_key]
|
||||
field = self.__pydantic_fields__[field_key]
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
if not field.is_required() and field.default == v:
|
||||
continue
|
||||
|
||||
if by_alias and field_key in self.model_fields:
|
||||
dict_key = self.model_fields[field_key].alias or field_key
|
||||
if by_alias and field_key in self.__pydantic_fields__:
|
||||
dict_key = self.__pydantic_fields__[field_key].alias or field_key
|
||||
else:
|
||||
dict_key = field_key
|
||||
|
||||
@@ -200,7 +200,7 @@ def _calculate_keys(
|
||||
include: MappingIntStrAny | None,
|
||||
exclude: MappingIntStrAny | None,
|
||||
exclude_unset: bool,
|
||||
update: typing.Dict[str, Any] | None = None, # noqa UP006
|
||||
update: dict[str, Any] | None = None, # noqa UP006
|
||||
) -> typing.AbstractSet[str] | None:
|
||||
if include is None and exclude is None and exclude_unset is False:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user