Skip to content
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

Make mypy ignore CoreSchema's typing #528

Merged
merged 2 commits into from
Apr 7, 2023
Merged
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
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:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MyPy looks for the name MYPY and ignores elif False. Pyright needs the elif False to not complain about CoreSchema getting re-defined.

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