Skip to content

Commit 8ee844e

Browse files
authored
Merge branch 'main' into feat/use-eitherfloat
2 parents ca38362 + 875befe commit 8ee844e

33 files changed

+736
-441
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!-- Thank you for your contribution! -->
2+
3+
## Change Summary
4+
5+
<!-- Please give a short summary of the changes. -->
6+
7+
## Related issue number
8+
9+
<!-- Are there any issues opened that will be resolved by merging this change? -->
10+
<!-- WARNING: please use "fix #123" style references so the issue is closed when this PR is merged. -->
11+
12+
## Checklist
13+
14+
* [ ] Unit tests for the changes exist
15+
* [ ] Documentation reflects the changes where applicable
16+
* [ ] Pydantic tests pass with this `pydantic-core` (except for expected changes)
17+
* [ ] My PR is ready to review, **please add a comment including the phrase "please review" to assign reviewers**

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ jobs:
151151
python-version: '3.11'
152152

153153
- run: pip install -r tests/requirements.txt
154-
- run: 'pip install "maturin>=0.15,<0.16" typing_extensions'
154+
- run: 'pip install "maturin>=1,<2" typing_extensions'
155155
- run: make build-dev
156156

157157
- run: pip freeze
@@ -254,7 +254,7 @@ jobs:
254254
version: '3.1.32'
255255
actions-cache-folder: emsdk-cache
256256

257-
- run: pip install 'maturin>=0.15,<0.16' 'black>=22.3.0,<23' typing_extensions
257+
- run: pip install 'maturin>=1,<2' 'black>=22.3.0,<23' typing_extensions
258258

259259
- name: build wheels
260260
run: make build-wasm
@@ -361,6 +361,7 @@ jobs:
361361
architecture: ${{ matrix.python-architecture || 'x64' }}
362362

363363
- run: pip install -U twine 'black>=22.3.0,<23' typing_extensions
364+
364365
# generate self-schema now, so we don't have to do so inside docker in maturin build
365366
- run: python generate_self_schema.py
366367

@@ -380,6 +381,7 @@ jobs:
380381
container: ${{ matrix.container }}
381382
args: --release --out dist --interpreter ${{ matrix.interpreter || '3.7 3.8 3.9 3.10 3.11 pypy3.7 pypy3.8 pypy3.9' }}
382383
rust-toolchain: stable
384+
docker-options: -e CI
383385

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

.github/workflows/codspeed.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ jobs:
4646
- name: cache rust
4747
uses: Swatinem/rust-cache@v2
4848

49-
- run: pip install . -v
49+
- name: Install pydantic-core
50+
# build-prod does not include MiMalloc because it bypasses Maturin
51+
run: |
52+
pip install -e .
53+
make build-prod
54+
python -c 'import pydantic_core'
5055
env:
5156
CONST_RANDOM_SEED: 0 # Fix the compile time RNG seed
5257

Cargo.lock

Lines changed: 52 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pydantic-core"
3-
version = "0.38.0"
3+
version = "0.41.0"
44
edition = "2021"
55
license = "MIT"
66
homepage = "https://github.com/pydantic/pydantic-core"
@@ -26,15 +26,15 @@ include = [
2626
]
2727

2828
[dependencies]
29-
pyo3 = "0.18.2"
29+
pyo3 = "0.19.0"
3030
regex = "1.6.0"
31-
strum = { version = "0.24.1", features = ["derive"] }
31+
strum = { version = "0.25.0", features = ["derive"] }
3232
strum_macros = "0.24.3"
3333
serde_json = {version = "1.0.87", features = ["preserve_order"]}
3434
enum_dispatch = "0.3.8"
3535
serde = "1.0.147"
3636
mimalloc = { version = "0.1.30", default-features = false, optional = true }
37-
speedate = "0.8.1"
37+
speedate = "0.9.0"
3838
ahash = "0.8.0"
3939
url = "2.3.1"
4040
# idna is already required by url, added here to be explicit
@@ -51,17 +51,23 @@ crate-type = ["cdylib", "rlib"]
5151
extension-module = ["pyo3/extension-module"]
5252
# required for cargo bench
5353
auto-initialize = ["pyo3/auto-initialize"]
54-
default = ["mimalloc", "mimalloc/local_dynamic_tls", "pyo3/generate-import-lib", "pyo3/num-bigint"]
54+
# disabled for benchmarks since it makes microbenchmark performance more flakey
55+
mimalloc-allocator = ["mimalloc", "mimalloc/local_dynamic_tls"]
56+
default = ["pyo3/generate-import-lib", "pyo3/num-bigint"]
5557

5658
[profile.release]
5759
lto = "fat"
5860
codegen-units = 1
5961
strip = true
6062

63+
[profile.bench]
64+
debug = true
65+
strip = false
66+
6167
[dev-dependencies]
62-
pyo3 = { version = "0.18.2", features = ["auto-initialize"] }
68+
pyo3 = { version = "0.19.0", features = ["auto-initialize"] }
6369

6470
[build-dependencies]
6571
version_check = "0.9.4"
6672
# used where logic has to be version/distribution specific, e.g. pypy
67-
pyo3-build-config = "0.18.2"
73+
pyo3-build-config = "0.19.0"

build.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@ use std::str::from_utf8;
66
fn generate_self_schema() {
77
println!("cargo:rerun-if-changed=pydantic_core/core_schema.py");
88
println!("cargo:rerun-if-changed=generate_self_schema.py");
9-
if Path::new("./src/self_schema.py").exists() && option_env!("DEBIAN_FRONTEND") == Some("noninteractive") {
10-
// self_schema.py already exists and DEBIAN_FRONTEND indicates we're in a maturin build,
11-
// skip running generate_self_schema.py
9+
if Path::new("./src/self_schema.py").exists() && option_env!("CI") == Some("true") {
10+
// self_schema.py already exists and CI indicates we're running on a github actions build,
11+
// don't bother generating again
1212
return;
1313
}
14-
let output = Command::new(env::var("PYTHON").unwrap_or_else(|_| "python3".to_owned()))
15-
.arg("generate_self_schema.py")
16-
.output()
17-
.expect("failed to execute process");
14+
15+
let output = Command::new(
16+
env::var("PYTHON")
17+
.ok()
18+
.or_else(|| pyo3_build_config::get().executable.clone())
19+
.unwrap_or_else(|| "python3".to_owned()),
20+
)
21+
.arg("generate_self_schema.py")
22+
.output()
23+
.expect("failed to execute process");
1824

1925
if !output.status.success() {
2026
let stdout = from_utf8(&output.stdout).unwrap();

generate_self_schema.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def tagged_union(std_union_schema: Dict[str, Any], discriminator_key: str, ref:
9595
first, *rest = literal
9696
tagged_choices[first] = choice
9797
for arg in rest:
98-
tagged_choices[arg] = first
98+
tagged_choices[arg] = choice
9999
s = {'type': 'tagged-union', 'discriminator': discriminator_key, 'choices': tagged_choices}
100100
if ref is not None:
101101
s['ref'] = ref
@@ -129,15 +129,8 @@ def type_dict_schema(typed_dict) -> dict[str, Any]: # noqa: C901
129129
schema = {'type': 'list', 'items_schema': schema_ref_validator}
130130
elif fr_arg == 'Dict[str, CoreSchema]':
131131
schema = {'type': 'dict', 'keys_schema': {'type': 'str'}, 'values_schema': schema_ref_validator}
132-
elif fr_arg == 'Dict[Union[str, int], Union[str, int, CoreSchema]]':
133-
schema = {
134-
'type': 'dict',
135-
'keys_schema': {'type': 'union', 'choices': [{'type': 'str'}, {'type': 'int'}]},
136-
'values_schema': {
137-
'type': 'union',
138-
'choices': [{'type': 'str'}, {'type': 'int'}, schema_ref_validator],
139-
},
140-
}
132+
elif fr_arg == 'Dict[Hashable, CoreSchema]':
133+
schema = {'type': 'dict', 'keys_schema': {'type': 'any'}, 'values_schema': schema_ref_validator}
141134
else:
142135
raise ValueError(f'Unknown Schema forward ref: {fr_arg}')
143136
else:

pydantic_core/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
PydanticOmit,
1010
PydanticSerializationError,
1111
PydanticSerializationUnexpectedValue,
12+
PydanticUndefined,
1213
SchemaError,
1314
SchemaSerializer,
1415
SchemaValidator,
@@ -42,6 +43,7 @@
4243
'Url',
4344
'MultiHostUrl',
4445
'ArgsKwargs',
46+
'PydanticUndefined',
4547
'SchemaError',
4648
'ErrorDetails',
4749
'InitErrorDetails',

pydantic_core/_pydantic_core.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ class ArgsKwargs:
267267
@property
268268
def kwargs(self) -> 'dict[str, Any] | None': ...
269269

270+
PydanticUndefined: object
271+
270272
def list_all_errors() -> 'list[ErrorTypeInfo]':
271273
"""
272274
Get information about all built-in errors.

0 commit comments

Comments
 (0)