Showing with 2,774 additions and 1,780 deletions.
  1. +4 −0 .github/dependabot.yml
  2. +47 −78 .github/workflows/ci.yml
  3. +4 −6 .github/workflows/codspeed.yml
  4. +3 −0 .gitignore
  5. +58 −47 Cargo.lock
  6. +43 −15 Cargo.toml
  7. +3 −28 Makefile
  8. +1 −1 README.md
  9. +2 −2 generate_self_schema.py
  10. +1 −2 pyproject.toml
  11. +19 −1 python/pydantic_core/_pydantic_core.pyi
  12. +86 −35 python/pydantic_core/core_schema.py
  13. +0 −6 src/argument_markers.rs
  14. +47 −47 src/definitions.rs
  15. +34 −49 src/errors/line_error.rs
  16. +1 −1 src/errors/mod.rs
  17. +6 −1 src/errors/types.rs
  18. +47 −21 src/errors/validation_exception.rs
  19. +5 −4 src/errors/value_exception.rs
  20. +5 −5 src/input/datetime.rs
  21. +9 −17 src/input/input_abstract.rs
  22. +29 −26 src/input/input_json.rs
  23. +19 −31 src/input/input_python.rs
  24. +10 −21 src/input/input_string.rs
  25. +29 −29 src/input/return_enums.rs
  26. +7 −18 src/input/shared.rs
  27. +10 −12 src/lib.rs
  28. +15 −26 src/lookup_key.rs
  29. +172 −29 src/recursion_guard.rs
  30. +4 −0 src/serializers/computed_fields.rs
  31. +64 −80 src/serializers/config.rs
  32. +31 −29 src/serializers/extra.rs
  33. +162 −95 src/serializers/fields.rs
  34. +100 −73 src/serializers/infer.rs
  35. +10 −8 src/serializers/mod.rs
  36. +17 −20 src/serializers/ob_type.rs
  37. +25 −23 src/serializers/shared.rs
  38. +10 −7 src/serializers/type_serializers/bytes.rs
  39. +59 −17 src/serializers/type_serializers/dataclass.rs
  40. +16 −17 src/serializers/type_serializers/definitions.rs
  41. +2 −2 src/serializers/type_serializers/literal.rs
  42. +18 −10 src/serializers/type_serializers/simple.rs
  43. +12 −14 src/serializers/type_serializers/timedelta.rs
  44. +141 −208 src/serializers/type_serializers/tuple.rs
  45. +21 −7 src/tools.rs
  46. +1 −1 src/validators/any.rs
  47. +13 −10 src/validators/arguments.rs
  48. +1 −1 src/validators/bool.rs
  49. +2 −2 src/validators/bytes.rs
  50. +2 −1 src/validators/call.rs
  51. +1 −1 src/validators/callable.rs
  52. +1 −1 src/validators/chain.rs
  53. +3 −2 src/validators/custom_error.rs
  54. +31 −14 src/validators/dataclass.rs
  55. +2 −2 src/validators/date.rs
  56. +55 −6 src/validators/datetime.rs
  57. +5 −13 src/validators/decimal.rs
  58. +21 −32 src/validators/definitions.rs
  59. +9 −12 src/validators/dict.rs
  60. +2 −2 src/validators/float.rs
  61. +1 −1 src/validators/frozenset.rs
  62. +12 −12 src/validators/function.rs
  63. +3 −3 src/validators/generator.rs
  64. +2 −2 src/validators/int.rs
  65. +1 −1 src/validators/is_instance.rs
  66. +1 −1 src/validators/is_subclass.rs
  67. +49 −9 src/validators/json.rs
  68. +1 −1 src/validators/json_or_python.rs
  69. +1 −1 src/validators/lax_or_strict.rs
  70. +1 −1 src/validators/list.rs
  71. +6 −3 src/validators/literal.rs
  72. +41 −36 src/validators/mod.rs
  73. +10 −8 src/validators/model.rs
  74. +12 −12 src/validators/model_fields.rs
  75. +1 −1 src/validators/none.rs
  76. +1 −1 src/validators/nullable.rs
  77. +1 −1 src/validators/set.rs
  78. +2 −2 src/validators/string.rs
  79. +1 −1 src/validators/time.rs
  80. +1 −1 src/validators/timedelta.rs
  81. +267 −144 src/validators/tuple.rs
  82. +9 −10 src/validators/typed_dict.rs
  83. +20 −30 src/validators/union.rs
  84. +10 −14 src/validators/url.rs
  85. +8 −6 src/validators/uuid.rs
  86. +9 −3 src/validators/validation_state.rs
  87. +7 −5 src/validators/with_default.rs
  88. +9 −5 tests/benchmarks/complete_schema.py
  89. +16 −4 tests/benchmarks/test_micro_benchmarks.py
  90. +62 −1 tests/benchmarks/test_serialization_micro.py
  91. +4 −4 tests/requirements-linting.txt
  92. +12 −7 tests/requirements.txt
  93. +1 −1 tests/serializers/test_any.py
  94. +35 −1 tests/serializers/test_bytes.py
  95. +12 −10 tests/serializers/test_list_tuple.py
  96. +3 −1 tests/serializers/test_model.py
  97. +1 −1 tests/serializers/test_none.py
  98. +116 −0 tests/serializers/test_union.py
  99. +2 −2 tests/test_docstrings.py
  100. +66 −0 tests/test_errors.py
  101. +5 −5 tests/test_hypothesis.py
  102. +1 −11 tests/test_schema_functions.py
  103. +2 −2 tests/test_typing.py
  104. +60 −54 tests/validators/test_arguments.py
  105. +142 −0 tests/validators/test_dataclasses.py
  106. +12 −3 tests/validators/test_datetime.py
  107. +10 −0 tests/validators/test_definitions.py
  108. +3 −3 tests/validators/test_definitions_recursive.py
  109. +2 −2 tests/validators/test_frozenset.py
  110. +11 −4 tests/validators/test_int.py
  111. +29 −7 tests/validators/test_json.py
  112. +2 −2 tests/validators/test_list.py
  113. +2 −2 tests/validators/test_set.py
  114. +60 −64 tests/validators/test_tuple.py
  115. +32 −0 tests/validators/test_union.py
  116. +14 −1 tests/validators/test_uuid.py
  117. +13 −5 tests/validators/test_with_default.py
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ updates:
directory: "/"
schedule:
interval: "monthly"
groups:
python-packages:
patterns:
- "*"

- package-ecosystem: "github-actions"
directory: "/"
Expand Down
125 changes: 47 additions & 78 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- run: rustup component add llvm-tools-preview

- name: set up python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'

Expand Down Expand Up @@ -65,14 +65,11 @@ jobs:
fail-fast: false
matrix:
python-version:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- 'pypy3.7'
- 'pypy3.8'
- 'pypy3.9'
- 'pypy3.10'

Expand All @@ -90,7 +87,7 @@ jobs:
key: test-v3

- name: set up python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -127,7 +124,7 @@ jobs:
key: ${{ matrix.os }}-v1

- name: set up python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'

Expand Down Expand Up @@ -158,7 +155,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: set up python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -191,7 +188,7 @@ jobs:
path: pydantic-core

- name: set up python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'

Expand Down Expand Up @@ -233,7 +230,7 @@ jobs:
- name: cache rust
uses: Swatinem/rust-cache@v2

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'

Expand Down Expand Up @@ -279,7 +276,7 @@ jobs:
- name: cache rust
uses: Swatinem/rust-cache@v2

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'

Expand All @@ -294,7 +291,7 @@ jobs:

- name: set up python
id: setup-python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'

Expand All @@ -307,7 +304,7 @@ jobs:
- name: cache rust
uses: Swatinem/rust-cache@v2

- uses: mymindstorm/setup-emsdk@v12
- uses: mymindstorm/setup-emsdk@v13
with:
# NOTE!: as per https://github.com/pydantic/pydantic-core/pull/149 this version needs to match the version
# in node_modules/pyodide/repodata.json, to get the version, run:
Expand All @@ -332,7 +329,7 @@ jobs:
ls -lh dist/
ls -l dist/
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: wasm_wheels
path: dist
Expand All @@ -359,9 +356,9 @@ jobs:
command: sdist
args: --out dist
rust-toolchain: stable
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: pypi_files
name: pypi_files_sdist
path: dist

build:
Expand All @@ -385,19 +382,19 @@ jobs:
- os: linux
manylinux: auto
target: armv7
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12
interpreter: 3.8 3.9 3.10 3.11 3.12
- os: linux
manylinux: auto
target: ppc64le
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12
interpreter: 3.8 3.9 3.10 3.11 3.12
- os: linux
manylinux: auto
target: s390x
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12
interpreter: 3.8 3.9 3.10 3.11 3.12
- os: linux
manylinux: auto
target: x86_64
interpreter: pypy3.7 pypy3.8 pypy3.9 pypy3.10
interpreter: pypy3.9 pypy3.10

# musllinux
- os: linux
Expand All @@ -414,19 +411,19 @@ jobs:
target: x86_64
- os: macos
target: aarch64
interpreter: 3.7 3.8 3.9 pypy3.8 pypy3.9 pypy3.10
interpreter: 3.8 3.9 pypy3.9 pypy3.10

# windows;
# x86_64 pypy builds are not PGO optimized
# i686 not supported by pypy
# aarch64 only 3.11 and up, also not PGO optimized
- os: windows
target: x86_64
interpreter: pypy3.8 pypy3.9 pypy3.10
interpreter: pypy3.9 pypy3.10
- os: windows
target: i686
python-architecture: x86
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12
interpreter: 3.8 3.9 3.10 3.11 3.12
- os: windows
target: aarch64
interpreter: 3.11 3.12
Expand All @@ -436,7 +433,7 @@ jobs:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'
architecture: ${{ matrix.python-architecture || 'x64' }}
Expand All @@ -450,18 +447,18 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: ${{ matrix.manylinux == 'manylinux' && 'auto' || matrix.manylinux }}
args: --release --out dist --interpreter ${{ matrix.interpreter || '3.7 3.8 3.9 3.10 3.11 3.12 pypy3.7 pypy3.8 pypy3.9 pypy3.10' }}
manylinux: ${{ matrix.manylinux }}
args: --release --out dist --interpreter ${{ matrix.interpreter || '3.8 3.9 3.10 3.11 3.12 pypy3.9 pypy3.10' }}
rust-toolchain: stable
docker-options: -e CI

- run: ${{ (matrix.os == 'windows' && 'dir') || 'ls -lh' }} dist/

- run: twine check --strict dist/*

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: pypi_files
name: pypi_files_${{ matrix.os }}_${{ matrix.target }}_${{ matrix.interpreter || 'all' }}_${{ matrix.manylinux }}
path: dist

build-pgo:
Expand All @@ -472,7 +469,7 @@ jobs:
fail-fast: false
matrix:
os: [linux, windows, macos]
interpreter: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
interpreter: ['3.8', '3.9', '3.10', '3.11', '3.12']
include:
# standard runners with override for macos arm
- os: linux
Expand All @@ -484,8 +481,6 @@ jobs:
runs-on: macos-latest-xlarge
exclude:
# macos arm only supported from 3.10 and up
- os: macos
interpreter: '3.7'
- os: macos
interpreter: '3.8'
- os: macos
Expand All @@ -496,7 +491,7 @@ jobs:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.interpreter }}

Expand Down Expand Up @@ -556,9 +551,9 @@ jobs:

- run: ${{ matrix.ls || 'ls -lh' }} dist/

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: pypi_files_pgo
name: pypi_files_${{ matrix.os }}_${{ matrix.interpreter }}
path: dist

inspect-pypi-assets:
Expand All @@ -569,24 +564,13 @@ jobs:
- uses: actions/checkout@v4

- name: get dist artifacts
uses: actions/download-artifact@v3
with:
name: pypi_files
path: dist

- name: list dist files before PGO builds
run: |
ls -lh dist/
ls -l dist/
echo "`ls dist | wc -l` files"
- name: get PGO dist artifacts (comes after "get dist artifacts" to so these files override the non-PGO builds)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: pypi_files_pgo
pattern: pypi_files_*
merge-multiple: true
path: dist

- name: list dist files with PGO builds
- name: list dist files
run: |
ls -lh dist/
ls -l dist/
Expand Down Expand Up @@ -621,18 +605,13 @@ jobs:
- uses: actions/checkout@v4

- name: get dist artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: pypi_files
pattern: pypi_files_linux_*
merge-multiple: true
path: dist

- name: get PGO dist artifacts (comes after "get dist artifacts" to so these files override the non-PGO builds)
uses: actions/download-artifact@v3
with:
name: pypi_files_pgo
path: dist

- uses: uraimo/run-on-arch-action@v2.5.1
- uses: uraimo/run-on-arch-action@v2.6.0
name: install & test
with:
arch: ${{ matrix.target }}
Expand All @@ -643,11 +622,11 @@ jobs:
if command -v apt-get &> /dev/null; then
echo "installing python & pip with apt-get..."
apt-get update
apt-get install -y --no-install-recommends python3 python3-pip python3-venv
apt-get install -y --no-install-recommends python3 python3-pip python3-venv git
else
echo "installing python & pip with apk..."
apk update
apk add python3 py3-pip
apk add python3 py3-pip git
fi
run: |
set -x
Expand All @@ -674,20 +653,15 @@ jobs:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: get dist artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: pypi_files
path: dist

- name: get PGO dist artifacts (comes after "get dist artifacts" to so these files override the non-PGO builds)
uses: actions/download-artifact@v3
with:
name: pypi_files_pgo
pattern: pypi_files_*
merge-multiple: true
path: dist

- run: pip install typing-extensions
Expand All @@ -704,7 +678,7 @@ jobs:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'

Expand All @@ -714,15 +688,10 @@ jobs:
run: python .github/check_version.py

- name: get dist artifacts
uses: actions/download-artifact@v3
with:
name: pypi_files
path: dist

- name: get PGO dist artifacts (comes after "get dist artifacts" to so these files override the non-PGO builds)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: pypi_files_pgo
pattern: pypi_files_*
merge-multiple: true
path: dist

- run: twine check --strict dist/*
Expand All @@ -734,7 +703,7 @@ jobs:
TWINE_PASSWORD: ${{ secrets.pypi_token }}

- name: get wasm dist artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: wasm_wheels
path: wasm
Expand Down
Loading