Skip to content

Improve Meta overloads - #700

Merged
sobolevn merged 5 commits into
msgspec:mainfrom
adriangb:supports-pep746
Jul 13, 2026
Merged

Improve Meta overloads#700
sobolevn merged 5 commits into
msgspec:mainfrom
adriangb:supports-pep746

Conversation

@adriangb

@adriangb adriangb commented Jun 6, 2024

Copy link
Copy Markdown
Contributor

Also add some overloads to Meta to make it more type safe so e.g. Meta(gt=0, pattern=r'abc') is not allowed

@sobolevn

sobolevn commented Jul 3, 2026

Copy link
Copy Markdown
Member

I will finish this :)

@codspeed-hq

codspeed-hq Bot commented Jul 3, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 139 untouched benchmarks
⏩ 135 skipped benchmarks1


Comparing adriangb:supports-pep746 (7888c92) with main (ceb01c1)

Open in CodSpeed

Footnotes

  1. 135 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sobolevn
sobolevn requested review from Siyet and ofek July 13, 2026 07:10

@Siyet Siyet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@sobolevn sobolevn changed the title Add support for PEP 746 Improve Meta overloads Jul 13, 2026
@sobolevn

Copy link
Copy Markdown
Member

Yes, I renamed the PR. Full PEP-746 support is comming later on, I am working on it :)

@sobolevn
sobolevn added this pull request to the merge queue Jul 13, 2026
Merged via the queue into msgspec:main with commit 9fdf482 Jul 13, 2026
25 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants