From 19f7d414c58d6af544f39c3e4a0e62b0dca6ab7f Mon Sep 17 00:00:00 2001 From: Victorien <65306057+Viicos@users.noreply.github.com> Date: Fri, 25 Oct 2024 20:36:35 +0200 Subject: [PATCH] Use identity instead of equality when possible (#10712) --- pydantic/_internal/_decorators.py | 2 +- pydantic/_internal/_fields.py | 4 ++-- pydantic/_internal/_generate_schema.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pydantic/_internal/_decorators.py b/pydantic/_internal/_decorators.py index ee5104c5f4..bb0f7207ea 100644 --- a/pydantic/_internal/_decorators.py +++ b/pydantic/_internal/_decorators.py @@ -804,7 +804,7 @@ def count_positional_required_params(sig: Signature) -> int: # First argument is the value being validated/serialized, and can have a default value # (e.g. `float`, which has signature `(x=0, /)`). We assume other parameters (the info arg # for instance) should be required, and thus without any default value. - and (param.default is Parameter.empty or param == parameters[0]) + and (param.default is Parameter.empty or param is parameters[0]) ) diff --git a/pydantic/_internal/_fields.py b/pydantic/_internal/_fields.py index 1c03fadd58..32d0d6ed73 100644 --- a/pydantic/_internal/_fields.py +++ b/pydantic/_internal/_fields.py @@ -317,8 +317,8 @@ def collect_dataclass_fields( if ( not dataclass_field.init - and dataclass_field.default == dataclasses.MISSING - and dataclass_field.default_factory == dataclasses.MISSING + and dataclass_field.default is dataclasses.MISSING + and dataclass_field.default_factory is dataclasses.MISSING ): # TODO: We should probably do something with this so that validate_assignment behaves properly # Issue: https://github.com/pydantic/pydantic/issues/5470 diff --git a/pydantic/_internal/_generate_schema.py b/pydantic/_internal/_generate_schema.py index acd4cc7710..be5076fcd1 100644 --- a/pydantic/_internal/_generate_schema.py +++ b/pydantic/_internal/_generate_schema.py @@ -433,7 +433,7 @@ def get_json_schema(schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSc return json_schema # we don't want to add the missing to the schema if it's the default one - default_missing = getattr(enum_type._missing_, '__func__', None) == Enum._missing_.__func__ # type: ignore + default_missing = getattr(enum_type._missing_, '__func__', None) is Enum._missing_.__func__ # pyright: ignore[reportFunctionMemberAccess] enum_schema = core_schema.enum_schema( enum_type, cases,