Skip to content

fix(models): support PEP 604 unions in discriminator cache - #38

Open
danielgaskins wants to merge 1 commit into
parallel-web:mainfrom
danielgaskins:fix/pep604-union-cache
Open

danielgaskins wants to merge 1 commit into
parallel-web:mainfrom
danielgaskins:fix/pep604-union-cache

Conversation

@danielgaskins

Copy link
Copy Markdown

Fixes #20.

PEP 604 unions cannot be weakly referenced on Python 3.10 through 3.13. When response validation falls back to loose construction, the discriminator cache uses the raw union as a WeakKeyDictionary key and raises TypeError.

The cache now uses the equivalent typing.Union as its key on affected Python versions. The original PEP 604 type is still used for response parsing.

Added coverage for plain PEP 604 unions, discriminated unions, and repeated cache access.

Checked with:

  • 329 network-free tests using Pydantic 2
  • 316 passing tests and 13 expected skips using Pydantic 1
  • Ruff
  • Pyright
  • Mypy

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.

Error for template code in Task Group API (with python 3.12)

1 participant