Showing with 4,535 additions and 2,549 deletions.
  1. +3 −3 .github/dependabot.yml
  2. +61 −29 .github/workflows/ci.yml
  3. +153 −57 Cargo.lock
  4. +14 −12 Cargo.toml
  5. +6 −6 Makefile
  6. +44 −0 benches/main.rs
  7. +3 −8 pyproject.toml
  8. +2 −0 python/pydantic_core/__init__.py
  9. +18 −1 python/pydantic_core/_pydantic_core.pyi
  10. +8 −1 python/pydantic_core/core_schema.py
  11. +192 −64 src/definitions.rs
  12. +4 −2 src/errors/line_error.rs
  13. +9 −19 src/errors/location.rs
  14. +1 −1 src/errors/mod.rs
  15. +43 −19 src/errors/types.rs
  16. +6 −6 src/errors/validation_exception.rs
  17. +2 −2 src/errors/value_exception.rs
  18. +29 −139 src/input/input_abstract.rs
  19. +148 −180 src/input/input_json.rs
  20. +282 −256 src/input/input_python.rs
  21. +39 −40 src/input/input_string.rs
  22. +1 −3 src/input/mod.rs
  23. +0 −222 src/input/parse_json.rs
  24. +43 −10 src/input/return_enums.rs
  25. +17 −7 src/input/shared.rs
  26. +0 −63 src/lazy_index_map.rs
  27. +16 −1 src/lib.rs
  28. +13 −11 src/lookup_key.rs
  29. +8 −0 src/py_gc.rs
  30. +41 −1 src/serializers/config.rs
  31. +26 −1 src/serializers/errors.rs
  32. +1 −10 src/serializers/extra.rs
  33. +5 −5 src/serializers/filter.rs
  34. +27 −9 src/serializers/mod.rs
  35. +4 −1 src/serializers/ob_type.rs
  36. +1,299 −0 src/serializers/ser.rs
  37. +6 −5 src/serializers/shared.rs
  38. +2 −2 src/serializers/type_serializers/dataclass.rs
  39. +17 −15 src/serializers/type_serializers/definitions.rs
  40. +2 −2 src/serializers/type_serializers/dict.rs
  41. +102 −0 src/serializers/type_serializers/float.rs
  42. +4 −0 src/serializers/type_serializers/list.rs
  43. +1 −0 src/serializers/type_serializers/mod.rs
  44. +3 −3 src/serializers/type_serializers/model.rs
  45. +3 −3 src/serializers/type_serializers/nullable.rs
  46. +0 −1 src/serializers/type_serializers/simple.rs
  47. +1 −1 src/serializers/type_serializers/typed_dict.rs
  48. +8 −9 src/serializers/type_serializers/union.rs
  49. +3 −3 src/serializers/type_serializers/with_default.rs
  50. +2 −2 src/tools.rs
  51. +6 −14 src/validators/any.rs
  52. +8 −31 src/validators/arguments.rs
  53. +3 −14 src/validators/bool.rs
  54. +6 −30 src/validators/bytes.rs
  55. +2 −24 src/validators/call.rs
  56. +3 −13 src/validators/callable.rs
  57. +1 −15 src/validators/chain.rs
  58. +1 −13 src/validators/custom_error.rs
  59. +36 −54 src/validators/dataclass.rs
  60. +7 −15 src/validators/date.rs
  61. +4 −14 src/validators/datetime.rs
  62. +92 −70 src/validators/decimal.rs
  63. +18 −69 src/validators/definitions.rs
  64. +5 −22 src/validators/dict.rs
  65. +13 −37 src/validators/float.rs
  66. +9 −18 src/validators/frozenset.rs
  67. +20 −78 src/validators/function.rs
  68. +27 −40 src/validators/generator.rs
  69. +10 −34 src/validators/int.rs
  70. +1 −14 src/validators/is_instance.rs
  71. +1 −14 src/validators/is_subclass.rs
  72. +2 −22 src/validators/json.rs
  73. +2 −18 src/validators/json_or_python.rs
  74. +11 −18 src/validators/lax_or_strict.rs
  75. +31 −33 src/validators/list.rs
  76. +8 −20 src/validators/literal.rs
  77. +37 −54 src/validators/mod.rs
  78. +4 −17 src/validators/model.rs
  79. +37 −38 src/validators/model_fields.rs
  80. +0 −12 src/validators/none.rs
  81. +1 −13 src/validators/nullable.rs
  82. +10 −19 src/validators/set.rs
  83. +11 −32 src/validators/string.rs
  84. +3 −13 src/validators/time.rs
  85. +4 −14 src/validators/timedelta.rs
  86. +18 −58 src/validators/tuple.rs
  87. +36 −36 src/validators/typed_dict.rs
  88. +71 −130 src/validators/union.rs
  89. +16 −29 src/validators/url.rs
  90. +8 −14 src/validators/uuid.rs
  91. +37 −12 src/validators/validation_state.rs
  92. +1 −13 src/validators/with_default.rs
  93. +93 −0 tests/benchmarks/nested_schema.py
  94. +23 −0 tests/benchmarks/test_nested_benchmark.py
  95. +4 −5 tests/requirements-linting.txt
  96. +2 −2 tests/requirements.txt
  97. +8 −0 tests/serializers/test_any.py
  98. +7 −0 tests/serializers/test_bytes.py
  99. +21 −0 tests/serializers/test_definitions.py
  100. +1 −1 tests/serializers/test_functions.py
  101. +50 −0 tests/serializers/test_pickling.py
  102. +27 −0 tests/serializers/test_simple.py
  103. +56 −0 tests/serializers/test_union.py
  104. +4 −4 tests/test.rs
  105. +16 −4 tests/test_errors.py
  106. +7 −2 tests/test_garbage_collection.py
  107. +8 −1 tests/test_json.py
  108. +4 −0 tests/test_typing.py
  109. +4 −4 tests/validators/test_arguments.py
  110. +1 −1 tests/validators/test_bool.py
  111. +2 −0 tests/validators/test_date.py
  112. +2 −12 tests/validators/test_datetime.py
  113. +34 −1 tests/validators/test_decimal.py
  114. +210 −1 tests/validators/test_definitions_recursive.py
  115. +36 −2 tests/validators/test_float.py
  116. +13 −2 tests/validators/test_function.py
  117. +41 −4 tests/validators/test_int.py
  118. +1 −1 tests/validators/test_literal.py
  119. +53 −0 tests/validators/test_pickling.py
  120. +27 −2 tests/validators/test_string.py
  121. +3 −3 tests/validators/test_typed_dict.py
  122. +284 −14 tests/validators/test_union.py
  123. +150 −0 tests/validators/test_with_default.py
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"

- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"
90 changes: 61 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- '3.9'
- '3.10'
- '3.11'
- '3.12-dev'
- '3.12'
- 'pypy3.7'
- 'pypy3.8'
- 'pypy3.9'
Expand Down Expand Up @@ -214,7 +214,9 @@ jobs:

- run: pdm info && pdm list
working-directory: pydantic
- run: pdm run pytest
# Run pytest with lax xfail because we often add tests to pydantic
# which xfail on a pending release of pydantic-core
- run: pdm run pytest --override-ini=xfail_strict=False
working-directory: pydantic

lint:
Expand All @@ -236,7 +238,7 @@ jobs:
python-version: '3.11'

# used to lint js code
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '18'

Expand Down Expand Up @@ -313,12 +315,12 @@ jobs:
version: '3.1.32'
actions-cache-folder: emsdk-cache

- run: pip install 'maturin>=1,<2' 'black>=22.3.0,<23' typing_extensions
- run: pip install 'maturin>=1,<2' 'ruff==0.1.3' typing_extensions

- name: build wheels
run: make build-wasm

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '18'

Expand Down Expand Up @@ -389,7 +391,7 @@ jobs:
interpreter: 3.11 3.12
- os: macos
target: aarch64
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 pypy3.10
interpreter: 3.7 3.8 3.9 pypy3.8 pypy3.9 pypy3.10
- os: ubuntu
platform: linux
target: i686
Expand Down Expand Up @@ -440,7 +442,7 @@ jobs:
python-version: '3.11'
architecture: ${{ matrix.python-architecture || 'x64' }}

- run: pip install -U twine 'black>=22.3.0,<23' typing_extensions
- run: pip install -U twine 'ruff==0.1.3' typing_extensions

# generate self-schema now, so we don't have to do so inside docker in maturin build
- run: python generate_self_schema.py
Expand All @@ -465,54 +467,55 @@ jobs:
path: dist

build-pgo:
name: build pgo-optimized on ${{ matrix.platform || matrix.os }} (${{ matrix.interpreter}} - ${{ matrix.target }} - ${{ matrix.manylinux || 'auto' }})
name: build pgo-optimized on ${{ matrix.os }} / ${{ matrix.interpreter }}
# only run on push to main and on release
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Full Build')
strategy:
fail-fast: false
matrix:
os: [ubuntu, windows]
target: [x86_64]
manylinux: [auto]
interpreter: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev", "pypy3.7", "pypy3.8", "pypy3.9", "pypy3.10"]
os: [ubuntu-latest, windows-latest, macos-latest-xlarge]
interpreter: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
include:
- os: ubuntu
platform: linux
- os: windows
- os: windows-latest
ls: dir
- interpreter: 3.12-dev
maturin-interpreter: "3.12"

runs-on: ${{ matrix.os }}-latest
exclude:
- os: macos-latest-xlarge
interpreter: '3.7'
- os: macos-latest-xlarge
interpreter: '3.8'
- os: macos-latest-xlarge
interpreter: '3.9'

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

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

- name: install rust stable
id: rust-toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools

- run: pip install -U 'black>=22.3.0,<23' typing_extensions
- run: pip install -U 'ruff==0.1.3' typing_extensions

# generate self-schema now, so we don't have to do so inside docker in maturin build
- run: python generate_self_schema.py

- run: rustc --version --verbose

- name: build initial wheel
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: ${{ matrix.manylinux || 'auto' }}
manylinux: auto
args: >
--release
--out pgo-wheel
--interpreter ${{ matrix.maturin-interpreter || matrix.interpreter }}
--interpreter ${{ matrix.interpreter }}
rust-toolchain: stable
docker-options: -e CI
env:
Expand All @@ -536,12 +539,11 @@ jobs:
- name: build pgo-optimized wheel
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: ${{ matrix.manylinux || 'auto' }}
manylinux: auto
args: >
--release
--out dist
--interpreter ${{ matrix.maturin-interpreter || matrix.interpreter }}
--interpreter ${{ matrix.interpreter }}
rust-toolchain: stable
docker-options: -e CI
env:
Expand All @@ -551,7 +553,7 @@ jobs:

- uses: actions/upload-artifact@v3
with:
name: pypi_files
name: pypi_files_pgo
path: dist

inspect-pypi-assets:
Expand All @@ -567,7 +569,19 @@ jobs:
name: pypi_files
path: dist

- name: list dist files
- 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
with:
name: pypi_files_pgo
path: dist

- name: list dist files with PGO builds
run: |
ls -lh dist/
ls -l dist/
Expand Down Expand Up @@ -607,6 +621,12 @@ jobs:
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
path: dist

- uses: uraimo/run-on-arch-action@v2.5.1
name: install & test
with:
Expand Down Expand Up @@ -659,6 +679,12 @@ jobs:
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
path: dist

- run: pip install typing-extensions
- run: pip install -r tests/requirements.txt
- run: pip install pydantic-core --no-index --no-deps --find-links dist --force-reinstall
Expand Down Expand Up @@ -688,6 +714,12 @@ jobs:
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
path: dist

- run: twine check --strict dist/*

- name: upload to pypi
Expand Down
Loading