Skip to content

Commit 17f54c8

Browse files
authored
Merge branch 'main' into val_temporal_unit_2
2 parents 71b2ea6 + 4c4ac6e commit 17f54c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1510
-281
lines changed

‎.github/workflows/ci.yml‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
- '3.14t'
7373
- 'pypy3.10'
7474
- 'pypy3.11'
75+
- 'graalpy-3.11'
7576

7677
runs-on: ubuntu-latest
7778

@@ -329,8 +330,8 @@ jobs:
329330
- uses: mymindstorm/setup-emsdk@v14
330331
with:
331332
# NOTE!: as per https://github.com/pydantic/pydantic-core/pull/149 this version needs to match the version
332-
# in node_modules/pyodide/repodata.json, to get the version, run:
333-
# `cat node_modules/pyodide/repodata.json | python -m json.tool | rg platform`
333+
# in node_modules/pyodide/pyodide-lock.json, to get the version, run:
334+
# `cat node_modules/pyodide/pyodide-lock.json | jq .info.platform`
334335
version: '3.1.58'
335336
actions-cache-folder: emsdk-cache
336337

@@ -424,6 +425,10 @@ jobs:
424425
manylinux: auto
425426
target: x86_64
426427
interpreter: pypy3.10 pypy3.11
428+
- os: linux
429+
manylinux: auto
430+
target: x86_64
431+
interpreter: graalpy3.11
427432

428433
# musllinux
429434
- os: linux
@@ -485,6 +490,7 @@ jobs:
485490
args: --release --out dist --interpreter ${{ matrix.interpreter || '3.9 3.10 3.11 3.12 3.13 3.14 pypy3.10 pypy3.11' }}
486491
rust-toolchain: stable
487492
docker-options: -e CI
493+
before-script-linux: ${{ contains(matrix.interpreter, 'graalpy') && 'manylinux-interpreters ensure-all' || '' }}
488494

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

@@ -620,6 +626,8 @@ jobs:
620626
apk update
621627
apk add python3 py3-pip git curl
622628
fi
629+
env: |
630+
UV_NO_PROGRESS: '1'
623631
run: |
624632
set -x
625633
curl -LsSf https://astral.sh/uv/install.sh | sh
@@ -666,6 +674,7 @@ jobs:
666674

667675
permissions:
668676
id-token: write
677+
contents: write
669678

670679
steps:
671680
- uses: actions/checkout@v4

‎Cargo.lock‎

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

‎Cargo.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pydantic-core"
3-
version = "2.35.2"
3+
version = "2.37.2"
44
edition = "2021"
55
license = "MIT"
66
homepage = "https://github.com/pydantic/pydantic-core"
@@ -31,7 +31,7 @@ pyo3 = { version = "0.25", features = ["generate-import-lib", "num-bigint", "py-
3131
regex = "1.11.1"
3232
strum = { version = "0.27", features = ["derive"] }
3333
strum_macros = "0.27"
34-
serde_json = { version = "1.0.140", features = ["arbitrary_precision"] }
34+
serde_json = { version = "1.0.142", features = ["arbitrary_precision"] }
3535
enum_dispatch = "0.3.13"
3636
serde = { version = "1.0.219", features = ["derive"] }
3737
speedate = "0.17.0"

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"main": "tests/emscripten_runner.js",
99
"dependencies": {
1010
"prettier": "^2.7.1",
11-
"pyodide": "^0.26.3"
11+
"pyodide": "^0.27.7"
1212
},
1313
"scripts": {
1414
"test": "node tests/emscripten_runner.js",

‎pyproject.toml‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
[build-system]
2-
requires = ['maturin>=1,<2']
2+
requires = ['maturin>=1.9,<2']
33
build-backend = 'maturin'
44

55
[project]
66
name = 'pydantic_core'
77
description = "Core functionality for Pydantic validation and serialization"
88
requires-python = '>=3.9'
9+
license = 'MIT'
10+
license-files = ['LICENSE']
911
authors = [
1012
{ name = 'Samuel Colvin', email = '[email protected]' },
1113
{ name = 'Adrian Garcia Badaracco', email = '[email protected]' },
@@ -25,20 +27,22 @@ classifiers = [
2527
'Programming Language :: Python :: 3.12',
2628
'Programming Language :: Python :: 3.13',
2729
'Programming Language :: Python :: 3.14',
30+
'Programming Language :: Python :: Implementation :: CPython',
31+
'Programming Language :: Python :: Implementation :: PyPy',
32+
'Programming Language :: Python :: Implementation :: GraalPy',
2833
'Programming Language :: Rust',
2934
'Framework :: Pydantic',
3035
'Intended Audience :: Developers',
3136
'Intended Audience :: Information Technology',
32-
'License :: OSI Approved :: MIT License',
3337
'Operating System :: POSIX :: Linux',
3438
'Operating System :: Microsoft :: Windows',
3539
'Operating System :: MacOS',
3640
'Typing :: Typed',
3741
]
3842
dependencies = [
39-
'typing-extensions>=4.13.0',
43+
'typing-extensions>=4.14.1',
4044
]
41-
dynamic = ['license', 'readme', 'version']
45+
dynamic = ['readme', 'version']
4246

4347
[project.urls]
4448
Homepage = 'https://github.com/pydantic/pydantic-core'
@@ -160,3 +164,4 @@ fix = ["create", "fix"]
160164
# this ensures that `uv run` doesn't actually build the package; a `make`
161165
# command is needed to build
162166
package = false
167+
required-version = '>=0.7.2'

‎python/pydantic_core/__init__.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import sys as _sys
44
from typing import Any as _Any
55

6+
from typing_extensions import Sentinel
7+
68
from ._pydantic_core import (
79
ArgsKwargs,
810
MultiHostUrl,
@@ -40,6 +42,7 @@
4042

4143
__all__ = [
4244
'__version__',
45+
'UNSET',
4346
'CoreConfig',
4447
'CoreSchema',
4548
'CoreSchemaType',
@@ -140,3 +143,29 @@ class MultiHostHost(_TypedDict):
140143
"""The host part of this host, or `None`."""
141144
port: int | None
142145
"""The port part of this host, or `None`."""
146+
147+
148+
MISSING = Sentinel('MISSING')
149+
"""A singleton indicating a field value was not provided during validation.
150+
151+
This singleton can be used a default value, as an alternative to `None` when it has
152+
an explicit meaning. During serialization, any field with `MISSING` as a value is excluded
153+
from the output.
154+
155+
Example:
156+
```python
157+
from pydantic import BaseModel
158+
159+
from pydantic_core import MISSING
160+
161+
162+
class Configuration(BaseModel):
163+
timeout: int | None | MISSING = MISSING
164+
165+
166+
# configuration defaults, stored somewhere else:
167+
defaults = {'timeout': 200}
168+
169+
conf = Configuration.model_validate({...})
170+
timeout = conf.timeout if timeout.timeout is not MISSING else defaults['timeout']
171+
"""

‎python/pydantic_core/_pydantic_core.pyi‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ def to_json(
402402
exclude_none: bool = False,
403403
round_trip: bool = False,
404404
timedelta_mode: Literal['iso8601', 'float'] = 'iso8601',
405+
temporal_mode: Literal['iso8601', 'seconds', 'milliseconds'] = 'iso8601',
405406
bytes_mode: Literal['utf8', 'base64', 'hex'] = 'utf8',
406407
inf_nan_mode: Literal['null', 'constants', 'strings'] = 'constants',
407408
serialize_unknown: bool = False,
@@ -425,6 +426,9 @@ def to_json(
425426
exclude_none: Whether to exclude fields that have a value of `None`.
426427
round_trip: Whether to enable serialization and validation round-trip support.
427428
timedelta_mode: How to serialize `timedelta` objects, either `'iso8601'` or `'float'`.
429+
temporal_mode: How to serialize datetime-like objects (`datetime`, `date`, `time`), either `'iso8601'`, `'seconds'`, or `'milliseconds'`.
430+
`iso8601` returns an ISO 8601 string; `seconds` returns the Unix timestamp in seconds as a float; `milliseconds` returns the Unix timestamp in milliseconds as a float.
431+
428432
bytes_mode: How to serialize `bytes` objects, either `'utf8'`, `'base64'`, or `'hex'`.
429433
inf_nan_mode: How to serialize `Infinity`, `-Infinity` and `NaN` values, either `'null'`, `'constants'`, or `'strings'`.
430434
serialize_unknown: Attempt to serialize unknown types, `str(value)` will be used, if that fails
@@ -483,6 +487,7 @@ def to_jsonable_python(
483487
exclude_none: bool = False,
484488
round_trip: bool = False,
485489
timedelta_mode: Literal['iso8601', 'float'] = 'iso8601',
490+
temporal_mode: Literal['iso8601', 'seconds', 'milliseconds'] = 'iso8601',
486491
bytes_mode: Literal['utf8', 'base64', 'hex'] = 'utf8',
487492
inf_nan_mode: Literal['null', 'constants', 'strings'] = 'constants',
488493
serialize_unknown: bool = False,
@@ -504,6 +509,9 @@ def to_jsonable_python(
504509
exclude_none: Whether to exclude fields that have a value of `None`.
505510
round_trip: Whether to enable serialization and validation round-trip support.
506511
timedelta_mode: How to serialize `timedelta` objects, either `'iso8601'` or `'float'`.
512+
temporal_mode: How to serialize datetime-like objects (`datetime`, `date`, `time`), either `'iso8601'`, `'seconds'`, or `'milliseconds'`.
513+
`iso8601` returns an ISO 8601 string; `seconds` returns the Unix timestamp in seconds as a float; `milliseconds` returns the Unix timestamp in milliseconds as a float.
514+
507515
bytes_mode: How to serialize `bytes` objects, either `'utf8'`, `'base64'`, or `'hex'`.
508516
inf_nan_mode: How to serialize `Infinity`, `-Infinity` and `NaN` values, either `'null'`, `'constants'`, or `'strings'`.
509517
serialize_unknown: Attempt to serialize unknown types, `str(value)` will be used, if that fails
@@ -638,9 +646,6 @@ class ValidationError(ValueError):
638646
"""
639647
Python constructor for a Validation Error.
640648
641-
The API for constructing validation errors will probably change in the future,
642-
hence the static method rather than `__init__`.
643-
644649
Arguments:
645650
title: The title of the error, as used in the heading of `str(validation_error)`
646651
line_errors: A list of [`InitErrorDetails`][pydantic_core.InitErrorDetails] which contain information
@@ -988,7 +993,14 @@ def list_all_errors() -> list[ErrorTypeInfo]:
988993
class TzInfo(datetime.tzinfo):
989994
"""An `pydantic-core` implementation of the abstract [`datetime.tzinfo`][] class."""
990995

991-
# def __new__(cls, seconds: float) -> Self: ...
996+
def __init__(self, seconds: float = 0.0) -> None:
997+
"""Initializes the `TzInfo`.
998+
999+
Arguments:
1000+
seconds: The offset from UTC in seconds. Defaults to 0.0 (UTC).
1001+
"""
1002+
1003+
def __new__(cls, seconds: float = 0.0) -> Self: ...
9921004

9931005
# Docstrings for attributes sourced from the abstract base class, [`datetime.tzinfo`](https://docs.python.org/3/library/datetime.html#datetime.tzinfo).
9941006

0 commit comments

Comments
 (0)