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

Use core schema fns to initalize SchemaValidators in the test suite. #1631

Conversation

mikeedjones
Copy link
Contributor

@mikeedjones mikeedjones commented Feb 10, 2025

Change Summary

Changes the initialization of most of the SchemaValidators in the test suite to use core_schema.xxx_schema() functions instead of dicts, as proposed in #831, and explicitly calls the associated CoreConfig typed dicts for the config.

Related issue number

#831

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @sydney-runkle

Copy link

codecov bot commented Feb 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.58%. Comparing base (ab503cb) to head (a13eac8).
Report is 288 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1631      +/-   ##
==========================================
- Coverage   90.21%   89.58%   -0.63%     
==========================================
  Files         106      115       +9     
  Lines       16339    17905    +1566     
  Branches       36       25      -11     
==========================================
+ Hits        14740    16040    +1300     
- Misses       1592     1846     +254     
- Partials        7       19      +12     

see 66 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f1aaaaf...a13eac8. Read the comment docs.

Copy link

codspeed-hq bot commented Feb 10, 2025

CodSpeed Performance Report

Merging #1631 will not alter performance

Comparing mikeedjones:chore/use-core_schema-fn-to-initalize-validators (a13eac8) with main (f1aaaaf)

Summary

✅ 157 untouched benchmarks

@mikeedjones mikeedjones force-pushed the chore/use-core_schema-fn-to-initalize-validators branch from 37d4e29 to 3fa5d10 Compare February 10, 2025 15:09
@mikeedjones mikeedjones changed the title Chore/use core schema fn to initalize validators Use core schema fn to initalize validators Feb 10, 2025
@mikeedjones mikeedjones changed the title Use core schema fn to initalize validators Use core schema fns to initalize validators Feb 10, 2025
@mikeedjones
Copy link
Contributor Author

mikeedjones commented Feb 10, 2025

To track which SchemaValidator use the fns after this PR, and which are still be be converted. This is not exhaustive and is more for my convenience as opposed to anything else!

Validators

tests/test_misc.py
  • test_validation_error
  • test_validation_error_include_context
  • test_custom_title
  • test_validation_error_multiple
  • test_unicode_error_input_repr
tests/test_build.py
  • test_schema_as_string
  • test_pickle
  • test_not_schema_definition_error <- Should this be changed?
  • test_try_self_schema_discriminator
  • test_build_recursive_schema_from_defs
tests/test_json.py
  • test_bool
  • test_input_types
  • test_input_type_invalid
  • test_null
  • test_str
  • test_bytes
  • test_int
  • test_float
  • test_typed_dict
  • test_float_no_remainder
  • test_error_loc
  • test_dict
  • test_dict_any_value
  • test_json_invalid
  • test_to_jsonable_python_schema_serializer
  • test_json_bytes_base64_round_trip
  • test_json_bytes_base64_round_trip
  • test_json_bytes_base64_no_padding
  • test_json_bytes_base64_invalid
  • test_json_bytes_hex_round_trip
  • test_json_bytes_hex_round_trip
  • test_json_bytes_hex_invalid
tests/test_validate_strings.py
  • test_validate_strings
tests/validators/test_arguments.py
  • test_repr
  • test_build_missing_var_kwargs
  • test_build_missing_var_kwargs
  • test_error_display
tests/validators/test_union.py
  • test_union_bool_int
  • test_union_int_bool
  • test_nullable_via_union
  • test_union_list_bool_int
  • test_empty_choices
  • test_one_choice
  • test_strict_union
  • test_custom_error
  • test_custom_error_type
  • test_custom_error_type_context
  • test_int_float
  • test_int_float
  • test_left_to_right_union
  • test_smart_union_default_fallback
  • test_smart_union_model_field
  • test_smart_union_dataclass_field
  • test_smart_union_with_any
  • test_smart_union_with_any
  • test_smart_union_validator_function
  • test_smart_union_validator_function
  • test_smart_union_validator_function
  • test_smart_union_validator_function_one_arm
  • test_model_and_literal_union
  • test_more_specific_data_matches_subclass
  • test_fields_set_ensures_best_match
tests/validators/test_definitions_recursive.py
  • test_unused_ref
  • test_outside_parent
  • test_error_inside_definition_wrapper
  • test_recursive_definitions_schema
  • test_unsorted_definitions_schema
  • test_validate_assignment
  • test_cyclic_data
  • test_cyclic_data_threeway
tests/validators/test_with_default.py
  • test_typed_dict_default
  • test_typed_dict_omit
  • test_arguments
  • test_list
  • test_set
  • test_dict_keys
  • test_tuple_positional
  • test_tuple_positional_omit
  • test_on_error_default
  • test_factory_runtime_error
  • test_factory_missing_arg
  • test_typed_dict_error
  • test_on_error_default_not_int
  • test_on_error_default_factory
  • test_on_error_omit
  • test_on_error_wrong
  • test_model_class
  • test_validate_default
  • test_validate_default_factory
  • test_deepcopy_mutable_defaults
  • test_default_value
  • test_default_value_validate_default
  • test_default_value_validate_default_fail
  • test_default_value_validate_default_strict_pass
  • test_default_value_validate_default_strict_fail
  • test_some_pattern_match
  • test_some_pattern_match
tests/validators/test_pickling.py
  • test_basic_schema_validator <- Should this be changed?
tests/validators/test_list.py
  • test_list_strict
  • test_list_no_copy
  • test_list_int
  • test_list_json
  • test_list_any
  • test_list_error
  • test_list_length_constraints
  • test_list_length_constraints_omit
  • test_length_ctx
  • test_list_function
  • test_list_function_val_error
  • test_list_function_internal_error
  • test_generator_error
  • test_list_from_dict_items
  • test_bad_iter
  • test_max_length_fail_fast
  • test_list_fail_fast
tests/validators/test_allow_partial.py
  • test_set_frozenset
  • test_dataclass
tests/validators/test_nullable.py
  • test_nullable
  • test_union_nullable_bool_int
  • test_leak_nullable
tests/validators/test_typed_dict.py
  • test_simple
  • test_strict
  • test_with_default
  • test_missing_error
  • test_config
  • test_ignore_extra
  • test_forbid_extra
  • test_str_config
  • test_json_error
  • test_fields_required_by_default
  • test_fields_required_by_default_with_optional
  • test_fields_required_by_default_with_default
  • test_all_optional_fields
  • test_all_optional_fields_with_required_fields
  • test_aliases_path_negative
  • test_aliases_debug
  • get_int_key
  • get_custom_getitem
  • test_alias_build_error
  • test_alias_build_error
  • test_alias_build_error
  • test_alias_build_error
  • test_alias_build_error
  • test_alias_build_error
  • test_empty_model
  • test_model_deep
  • test_with_default_factory
  • test_bad_default_factory
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_forbid
  • test_extra_behavior_forbid
  • test_extra_behavior_forbid
  • test_extra_behavior_forbid
  • test_extra_behavior_forbid
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
tests/validators/test_model_init.py
  • test_model_init
  • test_model_init_nested
  • test_function_before
  • test_function_after
  • test_function_wrap
  • test_simple
  • test_model_custom_init_nested
  • test_model_custom_init_extra
  • test_leak_model
  • test_model_custom_init_with_union
tests/validators/test_function.py
  • test_function_before_error
  • test_function_before_error_hide_input
  • test_function_before_error_model
  • test_function_after_config
  • test_class_with_validator
  • test_function_after_doesnt_change_mode
  • test_model_root_function_assignment
tests/validators/test_is_instance.py
  • test_validate_json
  • test_is_instance
  • test_is_instance_cases
  • test_is_instance_invalid
  • test_instancecheck
  • test_repr
  • test_is_type
  • test_is_instance_json_type_before_validator
  • test_is_instance_json_type_before_validator
tests/validators/test_tuple.py
  • test_any_no_copy
  • test_empty_positional_tuple
  • test_tuple_var_len_kwargs
  • test_tuple_var_len_errors
  • test_tuple_fix_len_errors
  • test_union_tuple_list
  • test_union_tuple_var_len
  • test_union_tuple_fix_len
  • test_tuple_fix_error
  • test_tuple_fix_extra
  • test_tuple_fix_extra_any
  • test_generator_error
  • test_frozenset_from_dict_items
  • test_length_constraints_omit
  • test_tuple_fail_fast
tests/validators/test_model_fields.py
  • test_simple
  • test_strict
  • test_with_default
  • test_missing_error
  • test_config
  • test_ignore_extra
  • test_forbid_extra
  • test_str_config
  • test_validate_assignment
  • test_validate_assignment_strict_field
  • test_validate_assignment_functions
  • test_validate_assignment_ignore_extra
  • test_validate_assignment_allow_extra
  • test_validate_assignment_allow_extra_validate
  • test_validate_assignment_with_strict
  • test_json_error
  • test_fields_required_by_default
  • test_fields_required_by_default_with_default
  • test_aliases_path_negative
  • test_aliases_debug
  • get_int_key
  • get_custom_getitem
  • test_alias_build_error
  • test_alias_build_error
  • test_alias_build_error
  • test_alias_build_error
  • test_alias_build_error
  • test_alias_build_error
  • test_empty_model
  • test_model_fields_deep
  • test_from_attributes
  • test_from_attributes_type_error
  • test_from_attributes_by_name
  • test_from_attributes_override_true
  • test_from_attributes_override_false
  • test_from_attributes_missing
  • test_from_attributes_error
  • test_from_attributes_extra
  • test_from_attributes_extra_ignore_no_attributes_accessed
  • test_from_attributes_extra_forbid
  • test_from_attributes_function
  • test_from_attributes_error_error
  • test_from_attributes_path
  • test_from_attributes_path_error
  • test_alias_extra_from_attributes
  • test_with_default_factory
  • test_bad_default_factory
  • test_frozen_field
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_forbid
  • test_extra_behavior_forbid
  • test_extra_behavior_forbid
  • test_extra_behavior_forbid
  • test_extra_behavior_forbid
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
tests/validators/test_json.py
  • test_enum
tests/validators/test_uuid.py
  • test_uuid
  • test_uuid_strict
  • test_uuid_version
  • test_uuid_deepcopy
  • test_uuid_copy
  • test_uuid_wrap_json
tests/validators/test_model.py
  • test_model_class_setattr
  • test_model_class_root_validator_wrap
  • test_model_class_root_validator_before
  • test_model_class_root_validator_after
  • test_function_ask
  • test_function_plain_ask
  • test_union_sub_schema
  • test_tagged_union_sub_schema
  • test_bad_sub_schema
  • test_model_class_function_after
  • test_model_class_instance_direct
  • test_model_class_instance_subclass
  • test_model_class_instance_subclass_revalidate
  • test_model_class_strict
  • test_model_class_strict_json
  • test_internal_error
  • test_revalidate_always
  • test_revalidate_subclass_instances
  • test_revalidate_extra
  • test_post_init
  • test_revalidate_post_init
  • test_post_init_validation_error
  • test_post_init_internal_error
  • test_post_init_mutate
  • test_validate_assignment
  • test_frozen
tests/validators/test_dataclasses.py
  • test_dataclass
  • test_dataclass_subclass
  • test_dataclass_post_init
  • test_dataclass_post_init_args
  • test_dataclass_post_init_args_multiple
  • test_dataclass_exact_validation
  • test_dataclass_field_after_validator
  • test_dataclass_field_plain_validator
  • test_dataclass_field_before_validator
  • test_dataclass_field_wrap_validator1
  • test_dataclass_field_wrap_validator2
  • test_dataclass_self_init
  • test_dataclass_self_init_alias
  • test_dataclass_self_init_alias_field_name
  • test_dataclass_self_init_post_init
  • test_dataclass_validate_assignment
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_ignore
  • test_extra_behavior_forbid
  • test_extra_behavior_forbid
  • test_extra_behavior_forbid
  • test_extra_behavior_forbid
  • test_extra_behavior_forbid
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_extra_behavior_allow
  • test_function_validator_wrapping_args_schema_after
  • test_function_validator_wrapping_args_schema_before
  • test_function_validator_wrapping_args_schema_wrap
  • test_custom_dataclass_names
  • test_slots
  • test_dataclass_slots_field_before_validator
  • test_dataclass_slots_field_after_validator
  • test_slots_dataclass_subclass
  • test_slots_mixed
  • test_dataclass_json
  • test_dataclass_wrap_json
  • fn
  • test_dataclass_args_init
  • test_dataclass_args_init_with_default
tests/validators/test_json_or_python.py
  • test_json_or_python
tests/benchmarks/test_serialization_micro.py
  • core_validator <- Should this be changed?
tests/benchmarks/test_micro_benchmarks.py
  • test_bool_core
  • core_model_validator
  • test_small_class_core_model
  • test_core_string_lax
  • test_core_string_lax_wrong
  • test_list_of_ints_core_json
  • test_list_of_strs_py_cached
  • test_list_of_strs_json_cached
  • test_set_of_ints_core_duplicates
  • test_set_of_ints_core_length
  • test_set_of_ints_core_json
  • test_set_of_ints_core_json_duplicates
  • test_frozenset_of_ints_core
  • test_frozenset_of_ints_duplicates_core
  • test_dict_of_ints_core
  • test_dict_of_any_core
  • test_dict_of_ints_core_json
  • test_dict_of_any_core
  • test_many_models_core_model
  • test_list_of_nullable_core
  • test_bytes_core
  • test_core_raw
  • test_core_str
  • test_core_future
  • test_core_future_str
  • validator
  • test_core_future
  • test_core_future_str
  • validator
  • test_core_future
  • test_core_raw
  • test_core_str
  • test_dont_raise_error
  • test_dont_raise_error_no_info
  • test_raise_error_value_error
  • test_raise_error_custom
  • test_positional_tuple
  • test_variable_tuple
  • test_tuple_many_variable
  • test_tuple_many_positional
  • test_chain_two_functions
  • test_variable_tuple
  • test_tuple_many_variable
  • test_tuple_many_positional
  • test_isinstance_json
  • test_int_error
  • test_definition_in_tree
  • test_definition_out_of_tree
  • test_model_instance
  • test_model_instance_abc
  • test_validate_literal
  • test_core_root_model
tests/benchmarks/nested_schema.py
  • inlined_schema <- Should this be changed?
  • schema_using_defs <- Should this be changed?
tests/serializers/test_other.py
  • test_serialize_with_extra_on_superclass
  • test_serialize_with_extra_on_superclass
tests/serializers/test_any.py
  • test_any_model
tests/serializers/test_serialize_as_any.py
  • test_serialize_as_any_with_models
  • test_serialize_as_any_with_models
  • test_serialize_as_any_with_dataclass
  • test_serialize_as_any_with_dataclass
  • test_serialize_as_any_with_typeddict
  • test_serialize_as_any_with_typeddict
  • test_serialize_as_any_with_unrelated_models
  • test_serialize_as_any_with_unrelated_models
tests/serializers/test_model.py
  • test_dataclass
  • test_advanced_exclude_nested_lists
  • test_extra
tests/serializers/test_dataclasses.py
  • test_extra_custom_serializer

@mikeedjones
Copy link
Contributor Author

please review :)

@mikeedjones mikeedjones changed the title Use core schema fns to initalize validators Use core schema fns to initalize SchemaValidators in the test suite. Feb 10, 2025
Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

A massive effort, thanks. Looks overall great, we should get this merged swiftly and without too much more changes lest it get unreviewable or too many merge conflicts.

Just one small set of questions I want to understand before merging...

Copy link
Contributor

Choose a reason for hiding this comment

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

Changes in this file look like they have removed cases unintentionally, perhaps revert this file?

@@ -1655,15 +1603,15 @@ def test_frozen_field():
'config,schema_extra_behavior_kw',
[
(core_schema.CoreConfig(extra_fields_behavior='allow'), {}),
(core_schema.CoreConfig(extra_fields_behavior='allow'), {'extra_behavior': None}),
(core_schema.CoreConfig(extra_fields_behavior='allow'), {}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar changes here and below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks! found a few more cases as well! thank you!

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM!

@davidhewitt davidhewitt merged commit 2e4134c into pydantic:main Feb 11, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants