Improve Meta overloads - #700
Conversation
|
I will finish this :) |
Merging this PR will not alter performance
Comparing Footnotes
|
Siyet
left a comment
There was a problem hiding this comment.
The overloads look right. I checked them against the runtime constraint validation across the full combination matrix (single constraints, every gt/ge x lt/le pairing, numeric mixed with pattern/min_length/max_length/tz, and metadata-only) and the type-checker verdict matches Meta.__init__'s runtime ValueErrors exactly, with no false positives or negatives: every combo the runtime rejects is a call-overload error, and every runtime-valid combo type-checks. mypy and pyrefly are both clean on basic_typing_examples.py; pyright is covered by CI plus the inline ignore markers. Nice that this lifts the runtime checks to type-check time.
One coordination note: #1116 (open) also edits the from typing_extensions import ... line (it adds disjoint_base), so whichever of these two lands second will need a trivial one-line rebase on that import.
Approving. One scope question, since the title mentions PEP 746: this diff is the type-safe Meta constructor overloads only, not the Annotated-metadata (__supertype__) side of PEP 746. Is that part still planned here, or is this PR now just the constructor overloads?
|
Yes, I renamed the PR. Full PEP-746 support is comming later on, I am working on it :) |
The 0.21.1 to 0.22.0 changelog batch (msgspec#1112) landed on 2026-07-03. Four user-visible changes merged between then and the 0.22.0 release on 2026-08-11 never got an entry: - msgspec#700, overloads on the `Meta` stub, so type checkers reject mixing `gt` with `ge` and `lt` with `le` - msgspec#1028, `null` placed last in the `anyOf` generated for optional unions - msgspec#1114, `__struct_encode_fields__` added to `src/msgspec/__init__.pyi` (its companion msgspec#813 only touched `tests/typing`, so it needs no entry of its own) - msgspec#1118, `json.encode` raising `TypeError` for a `dict` keyed by a plain `str`-valued `enum.Enum` I went over every PR merged in that window. The rest need no entry: msgspec#813 and msgspec#1117 are tests only, msgspec#1121 fixes an unreleased regression from msgspec#1028, msgspec#1145 is an unused variable under free-threaded builds, and msgspec#1146 and msgspec#1148 are CI and tooling. msgspec#1127, msgspec#1135 and msgspec#1080 already have entries. Docs build clean with `--fail-on-warning`. Note for whoever retries the release: the section is still headed `Version 0.22.0 (2026-08-11)`, and that date will need updating, since the tag was deleted after the upload failed. Refs msgspec#1134. Co-authored-by: Siyet <[email protected]>
Also add some overloads to Meta to make it more type safe so e.g.
Meta(gt=0, pattern=r'abc')is not allowed