GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing github.com — Support PEP 747 TypeForm in deserialization APIs by yukinarit · Pull Request #796 · yukinarit/pyserde Conversation
Owner
WhatAdds a
WhyEvery PEP 747 (Final, targets Python 3.15) adds HowA
Does this break downstream users?No — this was the main adoption risk, so it was tested explicitly.
Drive-by fixesTwo pre-existing bugs surfaced by the new overloads:
TestsNew Verified locally: Notes
🤖 Generated with Claude Code
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsEvery from_* entry point used a two-overload workaround: `type[T] -> T` for class objects, plus a `c: Any -> Any` catch-all commented "For Union, Optional etc.". The catch-all meant that passing a type expression silently degraded the return type to Any, including usages pyserde's own docs and doctests recommend, e.g. `from_dict(list[Foo], lst)`. PEP 747 `TypeForm[T]` describes the value of a type expression, so add a `TypeForm[T] -> T` overload to from_json, from_msgpack, from_yaml, from_toml, from_pickle, from_dict and from_tuple. `type[T]` stays first so plain-class calls resolve exactly as before. The `Any` overload stays last because tagging instances (Untagged, InternalTagging, AdjacentTagging) are objects, not type expressions, and cannot match TypeForm. Both checkers now infer `from_json(list[Foo], s)` as `list[Foo]`, `Optional[Foo]` as `Foo | None` and `Union[Foo, Bar]` as `Foo | Bar`. Downstream users need no configuration: mypy reports the "TypeForm is experimental" error only when checking the defining file, so a consumer importing pyserde from site-packages type-checks clean and still gets the precise inference. pyright without enableExperimentalFeatures resolves non-union forms precisely and falls back to Any for unions, i.e. exactly the previous behaviour. Two pre-existing bugs surfaced by the new overloads are fixed: * from_msgpack's implementation takes a `skip_none` parameter that was missing from both overloads, making it uncallable in typed code. * from_dict's `o: dict[str, Any]` was too narrow for non-dict targets; the doctest `from_dict(list[Foo], lst)` passes a list. Widened to Any on the non-class overloads only, so dataclass calls keep input checking. Add tests/test_typing.py using assert_type. It is a no-op at runtime, so it runs under pytest while pyright makes the real assertions via the existing pre-commit hook, guarding against a refactor collapsing the overloads back to Any. Raise the typing_extensions floor to >=4.13.0 (TypeForm landed in 4.13), enable it for mypy via enable_incomplete_feature and for pyright via enableExperimentalFeatures. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017M48r4aKMBGdbt4kcfVhmG
yukinarit
marked this pull request as ready for review
Uh oh!
There was an error while loading. Please reload this page.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
enhancement
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. | |||||||||||||||||||||
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |