updates
This commit is contained in:
@@ -26,11 +26,11 @@ from typing import (
|
||||
|
||||
from typing_extensions import dataclass_transform
|
||||
|
||||
from .class_validators import ValidatorGroup, extract_root_validators, extract_validators, inherit_validators
|
||||
from .config import BaseConfig, Extra, inherit_config, prepare_config
|
||||
from .error_wrappers import ErrorWrapper, ValidationError
|
||||
from .errors import ConfigError, DictError, ExtraError, MissingError
|
||||
from .fields import (
|
||||
from pydantic.v1.class_validators import ValidatorGroup, extract_root_validators, extract_validators, inherit_validators
|
||||
from pydantic.v1.config import BaseConfig, Extra, inherit_config, prepare_config
|
||||
from pydantic.v1.error_wrappers import ErrorWrapper, ValidationError
|
||||
from pydantic.v1.errors import ConfigError, DictError, ExtraError, MissingError
|
||||
from pydantic.v1.fields import (
|
||||
MAPPING_LIKE_SHAPES,
|
||||
Field,
|
||||
ModelField,
|
||||
@@ -39,11 +39,11 @@ from .fields import (
|
||||
Undefined,
|
||||
is_finalvar_with_default_val,
|
||||
)
|
||||
from .json import custom_pydantic_encoder, pydantic_encoder
|
||||
from .parse import Protocol, load_file, load_str_bytes
|
||||
from .schema import default_ref_template, model_schema
|
||||
from .types import PyObject, StrBytes
|
||||
from .typing import (
|
||||
from pydantic.v1.json import custom_pydantic_encoder, pydantic_encoder
|
||||
from pydantic.v1.parse import Protocol, load_file, load_str_bytes
|
||||
from pydantic.v1.schema import default_ref_template, model_schema
|
||||
from pydantic.v1.types import PyObject, StrBytes
|
||||
from pydantic.v1.typing import (
|
||||
AnyCallable,
|
||||
get_args,
|
||||
get_origin,
|
||||
@@ -53,7 +53,7 @@ from .typing import (
|
||||
resolve_annotations,
|
||||
update_model_forward_refs,
|
||||
)
|
||||
from .utils import (
|
||||
from pydantic.v1.utils import (
|
||||
DUNDER_ATTRIBUTES,
|
||||
ROOT_KEY,
|
||||
ClassAttribute,
|
||||
@@ -73,9 +73,9 @@ from .utils import (
|
||||
if TYPE_CHECKING:
|
||||
from inspect import Signature
|
||||
|
||||
from .class_validators import ValidatorListDict
|
||||
from .types import ModelOrDc
|
||||
from .typing import (
|
||||
from pydantic.v1.class_validators import ValidatorListDict
|
||||
from pydantic.v1.types import ModelOrDc
|
||||
from pydantic.v1.typing import (
|
||||
AbstractSetIntStr,
|
||||
AnyClassMethod,
|
||||
CallableGenerator,
|
||||
@@ -282,6 +282,12 @@ class ModelMetaclass(ABCMeta):
|
||||
cls = super().__new__(mcs, name, bases, new_namespace, **kwargs)
|
||||
# set __signature__ attr only for model class, but not for its instances
|
||||
cls.__signature__ = ClassAttribute('__signature__', generate_model_signature(cls.__init__, fields, config))
|
||||
|
||||
if not _is_base_model_class_defined:
|
||||
# Cython does not understand the `if TYPE_CHECKING:` condition in the
|
||||
# BaseModel's body (where annotations are set), so clear them manually:
|
||||
getattr(cls, '__annotations__', {}).clear()
|
||||
|
||||
if resolve_forward_refs:
|
||||
cls.__try_update_forward_refs__()
|
||||
|
||||
@@ -301,7 +307,7 @@ class ModelMetaclass(ABCMeta):
|
||||
|
||||
See #3829 and python/cpython#92810
|
||||
"""
|
||||
return hasattr(instance, '__fields__') and super().__instancecheck__(instance)
|
||||
return hasattr(instance, '__post_root_validators__') and super().__instancecheck__(instance)
|
||||
|
||||
|
||||
object_setattr = object.__setattr__
|
||||
@@ -669,7 +675,7 @@ class BaseModel(Representation, metaclass=ModelMetaclass):
|
||||
def schema_json(
|
||||
cls, *, by_alias: bool = True, ref_template: str = default_ref_template, **dumps_kwargs: Any
|
||||
) -> str:
|
||||
from .json import pydantic_encoder
|
||||
from pydantic.v1.json import pydantic_encoder
|
||||
|
||||
return cls.__config__.json_dumps(
|
||||
cls.schema(by_alias=by_alias, ref_template=ref_template), default=pydantic_encoder, **dumps_kwargs
|
||||
@@ -737,7 +743,6 @@ class BaseModel(Representation, metaclass=ModelMetaclass):
|
||||
exclude_defaults: bool,
|
||||
exclude_none: bool,
|
||||
) -> Any:
|
||||
|
||||
if isinstance(v, BaseModel):
|
||||
if to_dict:
|
||||
v_dict = v.dict(
|
||||
@@ -830,7 +835,6 @@ class BaseModel(Representation, metaclass=ModelMetaclass):
|
||||
exclude_defaults: bool = False,
|
||||
exclude_none: bool = False,
|
||||
) -> 'TupleGenerator':
|
||||
|
||||
# Merge field set excludes with explicit exclude parameter with explicit overriding field set options.
|
||||
# The extra "is not None" guards are not logically necessary but optimizes performance for the simple case.
|
||||
if exclude is not None or self.__exclude_fields__ is not None:
|
||||
|
||||
Reference in New Issue
Block a user