Skip to content

Add support for Python 3.14 #1714

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Add support for Python 3.14 #1714

wants to merge 1 commit into from

Conversation

Viicos
Copy link
Member

@Viicos Viicos commented May 18, 2025

Change Summary

Related issue number

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

Copy link

codspeed-hq bot commented May 18, 2025

CodSpeed Performance Report

Merging #1714 will not alter performance

Comparing python-3.14 (a6d92a4) with main (c0f4a7f)

Summary

✅ 157 untouched benchmarks

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.

Double segmentation fault, ouch.

@@ -71,7 +72,7 @@ linting = [{ include-group = "dev" }, 'griffe', 'pyright', 'ruff', 'mypy']
wasm = [{ include-group = "dev" }, 'typing_extensions', 'ruff']
codspeed = [
# codspeed is only run on CI, with latest version of CPython
'pytest-codspeed; python_version == "3.13" and implementation_name == "cpython"',
'pytest-codspeed; python_version == "3.14" and implementation_name == "cpython"',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'pytest-codspeed; python_version == "3.14" and implementation_name == "cpython"',
'pytest-codspeed; python_version == "3.13" and implementation_name == "cpython"',

(or update the benchmarks job)

@Viicos
Copy link
Member Author

Viicos commented May 19, 2025

Double segmentation fault, ouch.

We need to wait for uv to ship the beta1, things work with 3.14.0b1 built locally.

@davidhewitt
Copy link
Contributor

Ah yes, the ABI changed between alpha 6 which this CI ran with and beta 1, so it's no surprise stuff is broken.

@xtexx
Copy link

xtexx commented May 25, 2025

generate_self_schema.py also needs to be updated. Could you please merge xtexx@fc48a23 into this PR?

@Viicos
Copy link
Member Author

Viicos commented May 25, 2025

generate_self_schema.py also needs to be updated. Could you please merge xtexx@fc48a23 into this PR?

It is going to be removed in #1715.

@clin1234
Copy link

clin1234 commented May 27, 2025

Different situation for me testing with 3.14b1 free-threaded on Fedora:

Test output
(venv) cc@pretty:~/pydantic-core$ make
uv run ruff check --fix python/pydantic_core tests wasm-preview/run_tests.py
warning: `VIRTUAL_ENV=/home/cc/venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
All checks passed!
uv run ruff format python/pydantic_core tests wasm-preview/run_tests.py
warning: `VIRTUAL_ENV=/home/cc/venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
123 files left unchanged
cargo fmt
uv run maturin develop --uv
warning: `VIRTUAL_ENV=/home/cc/venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
📦 Including license file "/home/cc/pydantic-core/LICENSE"
🍹 Building a mixed python/rust project
🔗 Found pyo3 bindings
🐍 Found CPython 3.14t at /home/cc/pydantic-core/.venv/bin/python
📡 Using build options features, bindings from pyproject.toml
Audited 1 package in 0.86ms
   Compiling pydantic-core v2.34.1 (/home/cc/pydantic-core)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.74s
📦 Built wheel for CPython 3.14t to /tmp/.tmpdhYuy4/pydantic_core-2.34.1-cp314-cp314t-linux_x86_64.whl
✏  Setting installed package as editable
⚠ Warning: failed to set package as editable: failed to get version of install backend
🛠 Installed pydantic_core-2.34.1
uv run ruff check python/pydantic_core tests wasm-preview/run_tests.py
warning: `VIRTUAL_ENV=/home/cc/venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
All checks passed!
uv run ruff format --check python/pydantic_core tests wasm-preview/run_tests.py
warning: `VIRTUAL_ENV=/home/cc/venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
123 files already formatted
uv run griffe dump -f -d google -LWARNING -o/dev/null python/pydantic_core
warning: `VIRTUAL_ENV=/home/cc/venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
uv run python -m mypy.stubtest pydantic_core._pydantic_core --allowlist .mypy-stubtest-allowlist
warning: `VIRTUAL_ENV=/home/cc/venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
Success: no issues found in 1 module
cargo fmt --version
rustfmt 1.8.0-nightly (2805e1dc4c 2025-05-26)
cargo fmt --all -- --check
cargo clippy --version
clippy 0.1.89 (2805e1dc4c 2025-05-26)
cargo clippy --tests -- -D warnings
   Compiling pyo3-build-config v0.25.0
   Compiling pyo3-ffi v0.25.0
   Compiling pyo3-macros-backend v0.25.0
   Compiling pyo3 v0.25.0
   Compiling jiter v0.10.0
   Compiling pydantic-core v2.34.1 (/home/cc/pydantic-core)
   Compiling pyo3-macros v0.25.0
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 8.18s
uv run pytest
warning: `VIRTUAL_ENV=/home/cc/venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
=================================================== test session starts ====================================================
platform linux -- Python 3.14.0b1, pytest-8.3.4, pluggy-1.5.0
rootdir: /home/cc/pydantic-core
configfile: pyproject.toml
testpaths: tests
plugins: mock-3.14.0, speed-0.3.5, run-parallel-0.3.1, timeout-2.3.1, pretty-1.2.0, examples-0.0.15, inline-snapshot-0.19.3, hypothesis-6.124.2
timeout: 30.0s
timeout method: signal
timeout func_only: False
collected 5640 items                                                                                                       

tests/benchmarks/test_complete_benchmark.py ............                                                             [  0%]
tests/benchmarks/test_micro_benchmarks.py .......................................................................... [  1%]
.........................................                                                                            [  2%]
tests/benchmarks/test_nested_benchmark.py ..                                                                         [  2%]
tests/benchmarks/test_serialization_micro.py ..............................                                          [  2%]
tests/serializers/test_any.py ...............................s...................................................s.. [  4%]
...                                                                                                                  [  4%]
tests/serializers/test_bytes.py ................                                                                     [  4%]
tests/serializers/test_complex.py ..........                                                                         [  4%]
tests/serializers/test_dataclasses.py .....x..........                                                               [  5%]
tests/serializers/test_datetime.py ..................                                                                [  5%]
tests/serializers/test_decimal.py .......                                                                            [  5%]
tests/serializers/test_definitions.py .......                                                                        [  5%]
tests/serializers/test_definitions_recursive.py .....                                                                [  5%]
tests/serializers/test_dict.py ............................                                                          [  6%]
tests/serializers/test_enum.py .....                                                                                 [  6%]
tests/serializers/test_format.py ...............                                                                     [  6%]
tests/serializers/test_functions.py ................................                                                 [  7%]
tests/serializers/test_generator.py ......                                                                           [  7%]
tests/serializers/test_infer.py ...                                                                                  [  7%]
tests/serializers/test_json.py ....                                                                                  [  7%]
tests/serializers/test_json_or_python.py ..                                                                          [  7%]
tests/serializers/test_list_tuple.py ...............................................................                 [  8%]
tests/serializers/test_literal.py ......                                                                             [  8%]
tests/serializers/test_model.py .................................................................                    [  9%]
tests/serializers/test_model_root.py ........                                                                        [ 10%]
tests/serializers/test_none.py ............................                                                          [ 10%]
tests/serializers/test_nullable.py .                                                                                 [ 10%]
tests/serializers/test_other.py .......                                                                              [ 10%]
tests/serializers/test_pickling.py ......                                                                            [ 10%]
tests/serializers/test_serialize_as_any.py ........                                                                  [ 10%]
tests/serializers/test_set_frozenset.py .......                                                                      [ 11%]
tests/serializers/test_simple.py ..........................s............                                             [ 11%]
tests/serializers/test_string.py ...........                                                                         [ 11%]
tests/serializers/test_timedelta.py ...s                                                                             [ 11%]
tests/serializers/test_typed_dict.py ....................................                                            [ 12%]
tests/serializers/test_union.py .................................................................................... [ 14%]
......................                                                                                               [ 14%]
tests/serializers/test_url.py ..........                                                                             [ 14%]
tests/serializers/test_uuid.py .......                                                                               [ 14%]
tests/test_build.py .........                                                                                        [ 14%]
tests/test_config.py ..............                                                                                  [ 15%]
tests/test_custom_errors.py ....                                                                                     [ 15%]
tests/test_docstrings.py ............................................................                                [ 16%]
tests/test_errors.py ............................................................................................... [ 18%]
.................................................................s...............................                    [ 19%]
tests/test_garbage_collection.py F                                                                                   [ 19%]
tests/test_garbage_collection.py:22 test_gc_schema_serializer
tests/test_garbage_collection.py F                                                                                   [ 19%]
tests/test_garbage_collection.py:50 test_gc_schema_validator
tests/test_garbage_collection.py .                                                                                   [ 19%]
tests/test_hypothesis.py ....F                                                                                       [ 19%]
tests/test_hypothesis.py:92 test_recursive - pydantic_core._pydantic_core.ValidationError: 1 validation error fo…
tests/test_hypothesis.py ......                                                                                      [ 19%]
tests/test_isinstance.py .....                                                                                       [ 20%]
tests/test_json.py ..................................................                                                [ 20%]
tests/test_misc.py ...........F                                                                                      [ 21%]
tests/test_misc.py:160 test_core_schema_type_literal - AttributeError: 'str' object has no attribute '__forward_…
tests/test_misc.py ....                                                                                              [ 21%]
tests/test_prebuilt.py .......                                                                                       [ 21%]
tests/test_schema_functions.py ........................................................................F             [ 22%]
tests/test_schema_functions.py:333 test_all_schema_functions_used - AttributeError: 'str' object has no attribut…
tests/test_schema_functions.py .....                                                                                 [ 22%]
tests/test_strict.py ....................................                                                            [ 23%]
tests/test_typing.py ..........                                                                                      [ 23%]
tests/test_tzinfo.py ............                                                                                    [ 23%]
tests/test_validate_strings.py ....................                                                                  [ 24%]
tests/test_validation_context.py ........F                                                                           [ 24%]
tests/test_validation_context.py:64 test_isinstance[python] - AssertionError: Regex pattern did not match.  Rege…
tests/test_validation_context.py F                                                                                   [ 24%]
tests/test_validation_context.py:64 test_isinstance[json] - AssertionError: Regex pattern did not match.  Regex:…
tests/test_validation_context.py .                                                                                   [ 24%]
tests/validators/arguments_v3/test_alias.py .....sss.........sssss...s.s............................................ [ 25%]
....................................s                                                                                [ 26%]
tests/validators/arguments_v3/test_build_errors.py ......                                                            [ 26%]
tests/validators/arguments_v3/test_extra.py ....ss......ss..                                                         [ 26%]
tests/validators/arguments_v3/test_general.py ....s.ss......ssss...s...s.                                            [ 27%]
tests/validators/arguments_v3/test_keyword_only.py ....ss....s...s.                                                  [ 27%]
tests/validators/arguments_v3/test_positional_only.py ....ss...s.s                                                   [ 27%]
tests/validators/arguments_v3/test_positional_or_keyword.py ......ssss.....ss...s.                                   [ 28%]
tests/validators/arguments_v3/test_var_args.py .....ss.......ss....                                                  [ 28%]
tests/validators/arguments_v3/test_var_kwargs_uniform.py ....ss......ss....                                          [ 28%]
tests/validators/arguments_v3/test_var_kwargs_unpacked_typed_dict.py ...........sssss........                        [ 29%]
tests/validators/test_allow_partial.py ..............                                                                [ 29%]
tests/validators/test_arguments.py ..............s..s....s.........s.sssssss........ssssss.................sss...... [ 30%]
s..s.............s...sss.....s...s......ssss......sss....ssss...sss.....sssss.s.s................................... [ 32%]
.....................................................s                                                               [ 33%]
tests/validators/test_bool.py .......................................                                                [ 34%]
tests/validators/test_bytes.py ............................                                                          [ 35%]
tests/validators/test_call.py ..........................                                                             [ 35%]
tests/validators/test_callable.py ..............                                                                     [ 35%]
tests/validators/test_chain.py ............                                                                          [ 35%]
tests/validators/test_complex.py ...........................................                                         [ 36%]
tests/validators/test_custom_error.py .....                                                                          [ 36%]
tests/validators/test_dataclasses.py .......s..sss........sssss......s.............................................. [ 38%]
..............................................F                                                                      [ 39%]
tests/validators/test_dataclasses.py:1518 test_leak_dataclass[None]
tests/validators/test_dataclasses.py F                                                                               [ 39%]
tests/validators/test_dataclasses.py:1518 test_leak_dataclass[field]
tests/validators/test_dataclasses.py F                                                                               [ 39%]
tests/validators/test_dataclasses.py:1518 test_leak_dataclass[dataclass]
tests/validators/test_dataclasses.py ............................................................................... [ 40%]
...................s                                                                                                 [ 40%]
tests/validators/test_date.py ...................................................................................... [ 42%]
.....................                                                                                                [ 42%]
tests/validators/test_datetime.py .................................................................................. [ 44%]
.......................                                                                                              [ 44%]
tests/validators/test_decimal.py ................................................................................... [ 46%]
.................................................................................................................... [ 48%]
.................................................................................................................... [ 50%]
............................                                                                                         [ 50%]
tests/validators/test_definitions.py ...........                                                                     [ 50%]
tests/validators/test_definitions_recursive.py ....................................                                  [ 51%]
tests/validators/test_dict.py ................................                                                       [ 52%]
tests/validators/test_enums.py ..................s....                                                               [ 52%]
tests/validators/test_float.py ..................................................................................... [ 53%]
.................................................................................................................... [ 56%]
.................................................................................................................... [ 58%]
.....                                                                                                                [ 58%]
tests/validators/test_frozenset.py .........................................................................         [ 59%]
tests/validators/test_function.py .........................................................                          [ 60%]
tests/validators/test_generator.py ......................................                                            [ 61%]
tests/validators/test_int.py ....................................................................................... [ 62%]
.................................................................................................................... [ 64%]
..................................                                                                                   [ 65%]
tests/validators/test_is_instance.py .................................                                               [ 65%]
tests/validators/test_is_subclass.py ..............                                                                  [ 66%]
tests/validators/test_json.py .................................                                                      [ 66%]
tests/validators/test_json_or_python.py .                                                                            [ 66%]
tests/validators/test_lax_or_strict.py ..                                                                            [ 66%]
tests/validators/test_list.py ...................................................................................... [ 68%]
..........                                                                                                           [ 68%]
tests/validators/test_literal.py ..............................................                                      [ 69%]
tests/validators/test_model.py .........................................s                                            [ 70%]
tests/validators/test_model_fields.py .............................................................................. [ 71%]
.................................................................................................................... [ 73%]
.............................................................................................s                       [ 75%]
tests/validators/test_model_init.py ..........F                                                                      [ 75%]
tests/validators/test_model_init.py:413 test_leak_model[None]
tests/validators/test_model_init.py F                                                                                [ 75%]
tests/validators/test_model_init.py:413 test_leak_model[field]
tests/validators/test_model_init.py F                                                                                [ 75%]
tests/validators/test_model_init.py:413 test_leak_model[model]
tests/validators/test_model_init.py .                                                                                [ 75%]
tests/validators/test_model_root.py .........                                                                        [ 75%]
tests/validators/test_none.py ..                                                                                     [ 75%]
tests/validators/test_nullable.py ...                                                                                [ 75%]
tests/validators/test_pickling.py ....                                                                               [ 75%]
tests/validators/test_set.py ............................................................................            [ 77%]
tests/validators/test_string.py .................................................................................... [ 78%]
..........................                                                                                           [ 79%]
tests/validators/test_tagged_union.py ................................................                               [ 79%]
tests/validators/test_time.py .....................................................................................  [ 81%]
tests/validators/test_timedelta.py ................................................................................. [ 82%]
..s                                                                                                                  [ 82%]
tests/validators/test_tuple.py ..................................................................................... [ 84%]
....                                                                                                                 [ 84%]
tests/validators/test_typed_dict.py ................................................................................ [ 85%]
.................................................................................................................... [ 87%]
.....................................s                                                                               [ 88%]
tests/validators/test_union.py .....................................................x..............................  [ 90%]
tests/validators/test_url.py ....................................................................................... [ 91%]
.................................................................................................................... [ 93%]
.................................................................................................................... [ 95%]
...................                                                                                                  [ 96%]
tests/validators/test_uuid.py ...................................................................................... [ 97%]
...........                                                                                                          [ 97%]
tests/validators/test_with_default.py .............................................................................. [ 99%]
...........F                                                                                                         [ 99%]
tests/validators/test_with_default.py:638 test_leak_with_default
tests/validators/test_with_default.py .................................                                              [100%]

========================================================= FAILURES =========================================================
________________________________________________ test_gc_schema_serializer _________________________________________________
[XPASS(strict)] GC leaks on free-threaded
_________________________________________________ test_gc_schema_validator _________________________________________________
[XPASS(strict)] GC leaks on free-threaded
______________________________________________________ test_recursive ______________________________________________________

definition_schema = SchemaValidator(title="typed-dict", validator=DefinitionRef(
    DefinitionRefValidator {
        definition: "typed-d...ct: false, loc_by_alias: true, validate_by_alias: None, validate_by_name: None, cls_name: None })], cache_strings=True)

    @pytest.mark.skipif(sys.platform == 'emscripten', reason='Seems to fail sometimes on pyodide no idea why')
>   @given(strategies.from_type(BranchModel))

tests/test_hypothesis.py:94: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

definition_schema = SchemaValidator(title="typed-dict", validator=DefinitionRef(
    DefinitionRefValidator {
        definition: "typed-d...ct: false, loc_by_alias: true, validate_by_alias: None, validate_by_name: None, cls_name: None })], cache_strings=True)
data = {}

    @pytest.mark.skipif(sys.platform == 'emscripten', reason='Seems to fail sometimes on pyodide no idea why')
    @given(strategies.from_type(BranchModel))
    @pytest.mark.thread_unsafe  # https://github.com/Quansight-Labs/pytest-run-parallel/issues/20
    def test_recursive(definition_schema, data):
>       assert definition_schema.validate_python(data) == data
E       pydantic_core._pydantic_core.ValidationError: 1 validation error for typed-dict
E       name
E         Field required [type=missing, input_value={}, input_type=dict]
E           For further information visit https://errors.pydantic.dev/latest/v/missing
E       Falsifying example: test_recursive(
E           definition_schema=SchemaValidator(title="typed-dict", validator=DefinitionRef(
E               DefinitionRefValidator {
E                   definition: "typed-dict",
E               },
E           ), definitions=[TypedDict(TypedDictValidator { fields: [TypedDictField { name: "name", lookup_key_collection: LookupKeyCollection { by_name: Simple(LookupPath { first_item: PathItemString { key: "name", py_key: Py(0x523436b8840) }, rest: [] }), by_alias: None, by_alias_then_name: None }, name_py: Py(0x7faac1925f98), required: true, validator: Str(StrValidator { strict: false, coerce_numbers_to_str: false }) }, TypedDictField { name: "sub_branch", lookup_key_collection: LookupKeyCollection { by_name: Simple(LookupPath { first_item: PathItemString { key: "sub_branch", py_key: Py(0x52341840be0) }, rest: [] }), by_alias: None, by_alias_then_name: None }, name_py: Py(0x5233d6d5230), required: true, validator: WithDefault(WithDefaultValidator { default: Default(Py(0x7faac18e6e60)), on_error: Raise, validator: Nullable(NullableValidator { validator: DefinitionRef(DefinitionRefValidator { definition: "typed-dict" }), name: "nullable[...]" }), validate_default: false, copy_default: false, name: "default[nullable[...]]", undefined: Py(0x5233a570520) }) }], extra_behavior: Ignore, extras_validator: None, strict: false, loc_by_alias: true, validate_by_alias: None, validate_by_name: None, cls_name: None })], cache_strings=True),
E           data={},
E       )

tests/test_hypothesis.py:97: ValidationError
______________________________________________ test_core_schema_type_literal _______________________________________________

    def test_core_schema_type_literal():
        def get_type_value(schema):
            type_ = schema.__annotations__['type']
            m = re.search(r"Literal\['(.+?)']", type_.__forward_arg__)
            assert m, f'Unknown schema type: {type_}'
            return m.group(1)
    
>       schema_types = tuple(get_type_value(x) for x in CoreSchema.__args__)

tests/test_misc.py:168: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_misc.py:168: in <genexpr>
    schema_types = tuple(get_type_value(x) for x in CoreSchema.__args__)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

schema = <class 'pydantic_core.core_schema.InvalidSchema'>

    def get_type_value(schema):
        type_ = schema.__annotations__['type']
>       m = re.search(r"Literal\['(.+?)']", type_.__forward_arg__)
E       AttributeError: 'str' object has no attribute '__forward_arg__'

tests/test_misc.py:164: AttributeError
______________________________________________ test_all_schema_functions_used ______________________________________________

    def test_all_schema_functions_used():
        all_types = {
>           re.sub(r".+'(.+?)'.+", r'\1', s.__annotations__['type'].__forward_arg__)
            for s in core_schema.CoreSchema.__args__
        }
E       AttributeError: 'str' object has no attribute '__forward_arg__'

tests/test_schema_functions.py:336: AttributeError
_________________________________________________ test_isinstance[python] __________________________________________________

py_and_json = <class 'tests.conftest.py_and_json.<locals>.ChosenPyAndJsonValidator'>

    def test_isinstance(py_and_json: PyAndJson):
        def f(input_value, validator, info):
            if 'error' in info.context:
                raise ValueError('wrong')
            return validator(input_value)
    
        v = py_and_json(core_schema.with_info_wrap_validator_function(f, core_schema.str_schema()))
    
        assert v.validate_python('foobar', None, {}) == 'foobar'
    
        # internal error!, use generic bit of error message to match both cpython and pypy
        with pytest.raises(TypeError, match='is not iterable'):
>           v.validate_test('foobar')

tests/test_validation_context.py:77: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/conftest.py:83: in validate_test
    return self.validator.validate_python(py_input, strict=strict, context=context)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

input_value = 'foobar', validator = ValidatorCallable(Str(StrValidator { strict: false, coerce_numbers_to_str: false }))
info = ValidationInfo(config=None, context=None, data=None, field_name=None)

    def f(input_value, validator, info):
>       if 'error' in info.context:
E       TypeError: argument of type 'NoneType' is not a container or iterable

tests/test_validation_context.py:67: TypeError

During handling of the above exception, another exception occurred:

py_and_json = <class 'tests.conftest.py_and_json.<locals>.ChosenPyAndJsonValidator'>

    def test_isinstance(py_and_json: PyAndJson):
        def f(input_value, validator, info):
            if 'error' in info.context:
                raise ValueError('wrong')
            return validator(input_value)
    
        v = py_and_json(core_schema.with_info_wrap_validator_function(f, core_schema.str_schema()))
    
        assert v.validate_python('foobar', None, {}) == 'foobar'
    
        # internal error!, use generic bit of error message to match both cpython and pypy
>       with pytest.raises(TypeError, match='is not iterable'):
E       AssertionError: Regex pattern did not match.
E        Regex: 'is not iterable'
E        Input: "argument of type 'NoneType' is not a container or iterable"

tests/test_validation_context.py:76: AssertionError
__________________________________________________ test_isinstance[json] ___________________________________________________

py_and_json = <class 'tests.conftest.py_and_json.<locals>.ChosenPyAndJsonValidator'>

    def test_isinstance(py_and_json: PyAndJson):
        def f(input_value, validator, info):
            if 'error' in info.context:
                raise ValueError('wrong')
            return validator(input_value)
    
        v = py_and_json(core_schema.with_info_wrap_validator_function(f, core_schema.str_schema()))
    
        assert v.validate_python('foobar', None, {}) == 'foobar'
    
        # internal error!, use generic bit of error message to match both cpython and pypy
        with pytest.raises(TypeError, match='is not iterable'):
>           v.validate_test('foobar')

tests/test_validation_context.py:77: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/conftest.py:78: in validate_test
    return self.validator.validate_json(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

input_value = 'foobar', validator = ValidatorCallable(Str(StrValidator { strict: false, coerce_numbers_to_str: false }))
info = ValidationInfo(config=None, context=None, data=None, field_name=None)

    def f(input_value, validator, info):
>       if 'error' in info.context:
E       TypeError: argument of type 'NoneType' is not a container or iterable

tests/test_validation_context.py:67: TypeError

During handling of the above exception, another exception occurred:

py_and_json = <class 'tests.conftest.py_and_json.<locals>.ChosenPyAndJsonValidator'>

    def test_isinstance(py_and_json: PyAndJson):
        def f(input_value, validator, info):
            if 'error' in info.context:
                raise ValueError('wrong')
            return validator(input_value)
    
        v = py_and_json(core_schema.with_info_wrap_validator_function(f, core_schema.str_schema()))
    
        assert v.validate_python('foobar', None, {}) == 'foobar'
    
        # internal error!, use generic bit of error message to match both cpython and pypy
>       with pytest.raises(TypeError, match='is not iterable'):
E       AssertionError: Regex pattern did not match.
E        Regex: 'is not iterable'
E        Input: "argument of type 'NoneType' is not a container or iterable"

tests/test_validation_context.py:76: AssertionError
________________________________________________ test_leak_dataclass[None] _________________________________________________
[XPASS(strict)] GC leaks on free-threaded
________________________________________________ test_leak_dataclass[field] ________________________________________________
[XPASS(strict)] GC leaks on free-threaded
______________________________________________ test_leak_dataclass[dataclass] ______________________________________________
[XPASS(strict)] GC leaks on free-threaded
__________________________________________________ test_leak_model[None] ___________________________________________________
[XPASS(strict)] GC leaks on free-threaded
__________________________________________________ test_leak_model[field] __________________________________________________
[XPASS(strict)] GC leaks on free-threaded
__________________________________________________ test_leak_model[model] __________________________________________________
[XPASS(strict)] GC leaks on free-threaded
__________________________________________________ test_leak_with_default __________________________________________________
[XPASS(strict)] GC leaks on free-threaded
===================================================== inline snapshot ======================================================
                              Summary of Failures                               
┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃               ┃               ┃  Function     ┃              ┃               ┃
┃  File         ┃  Function     ┃  Line         ┃  Error Line  ┃  Error        ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│  tests/test…  │  test_gc_sc…  │  23           │              │               │
│  tests/test…  │  test_gc_sc…  │  51           │              │               │
│  tests/test…  │  test_recur…  │  93           │  94          │  Validation…  │
│  tests/test…  │  test_core_…  │  161          │  168         │  AttributeE…  │
│  tests/test…  │  test_all_s…  │  334          │  336         │  AttributeE…  │
│  tests/test…  │  test_isins…  │  65           │  76          │  AssertionE…  │
│  tests/test…  │  test_isins…  │  65           │  76          │  AssertionE…  │
│  tests/vali…  │  test_leak_…  │  1519         │              │               │
│  tests/vali…  │  test_leak_…  │  1519         │              │               │
│  tests/vali…  │  test_leak_…  │  1519         │              │               │
│  tests/vali…  │  test_leak_…  │  414          │              │               │
│  tests/vali…  │  test_leak_…  │  414          │              │               │
│  tests/vali…  │  test_leak_…  │  414          │              │               │
│  tests/vali…  │  test_leak_…  │  639          │              │               │
└───────────────┴───────────────┴───────────────┴──────────────┴───────────────┘
Results (12.29s):
        14 failed
      5501 passed
       123 skipped
         2 xfailed
make: *** [Makefile:107: test] Error 1

@clin1234 clin1234 mentioned this pull request May 27, 2025
4 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants