Skip to content

Commit

Permalink
Make mypy ignore CoreSchema's typing (#528)
Browse files Browse the repository at this point in the history
* Make mypy ignore CoreSchema's typing

* add comment

---------

Co-authored-by: Samuel Colvin <[email protected]>
  • Loading branch information
adriangb and samuelcolvin authored Apr 7, 2023
1 parent cc7a74e commit 534630f
Showing 1 changed file with 53 additions and 46 deletions.
99 changes: 53 additions & 46 deletions pydantic_core/core_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3283,52 +3283,59 @@ def definition_reference_schema(
return dict_not_none(type='definition-ref', schema_ref=schema_ref, metadata=metadata, serialization=serialization)


CoreSchema = Union[
AnySchema,
NoneSchema,
BoolSchema,
IntSchema,
FloatSchema,
StringSchema,
BytesSchema,
DateSchema,
TimeSchema,
DatetimeSchema,
TimedeltaSchema,
LiteralSchema,
IsInstanceSchema,
IsSubclassSchema,
CallableSchema,
ListSchema,
TuplePositionalSchema,
TupleVariableSchema,
SetSchema,
FrozenSetSchema,
GeneratorSchema,
DictSchema,
AfterValidatorFunctionSchema,
BeforeValidatorFunctionSchema,
WrapValidatorFunctionSchema,
PlainValidatorFunctionSchema,
WithDefaultSchema,
NullableSchema,
UnionSchema,
TaggedUnionSchema,
ChainSchema,
LaxOrStrictSchema,
TypedDictSchema,
ModelSchema,
DataclassArgsSchema,
DataclassSchema,
ArgumentsSchema,
CallSchema,
CustomErrorSchema,
JsonSchema,
UrlSchema,
MultiHostUrlSchema,
DefinitionsSchema,
DefinitionReferenceSchema,
]
MYPY = False
# See https://github.com/python/mypy/issues/14034 for details, in summary mypy is extremely slow to process this
# union which kills performance not just for pydantic, but even for code using pydantic
if not MYPY:
CoreSchema = Union[
AnySchema,
NoneSchema,
BoolSchema,
IntSchema,
FloatSchema,
StringSchema,
BytesSchema,
DateSchema,
TimeSchema,
DatetimeSchema,
TimedeltaSchema,
LiteralSchema,
IsInstanceSchema,
IsSubclassSchema,
CallableSchema,
ListSchema,
TuplePositionalSchema,
TupleVariableSchema,
SetSchema,
FrozenSetSchema,
GeneratorSchema,
DictSchema,
AfterValidatorFunctionSchema,
BeforeValidatorFunctionSchema,
WrapValidatorFunctionSchema,
PlainValidatorFunctionSchema,
WithDefaultSchema,
NullableSchema,
UnionSchema,
TaggedUnionSchema,
ChainSchema,
LaxOrStrictSchema,
TypedDictSchema,
ModelSchema,
DataclassArgsSchema,
DataclassSchema,
ArgumentsSchema,
CallSchema,
CustomErrorSchema,
JsonSchema,
UrlSchema,
MultiHostUrlSchema,
DefinitionsSchema,
DefinitionReferenceSchema,
]
elif False:
CoreSchema: TypeAlias = Dict[str, Any]


# to update this, call `pytest -k test_core_schema_type_literal` and copy the output
CoreSchemaType = Literal[
Expand Down

0 comments on commit 534630f

Please sign in to comment.