fix: NoneType parameters lose their default and their nullability - #321
Merged
Merged
Conversation
`SignatureItem.from_type` early-returned a bare `cls()` for `types.NoneType`,
discarding both the `default` it was handed and the nullability the annotation
implies. Every other branch threads `default` through. `absent_disposition` then
saw `default is UNSET` and `is_nullable is False` and classified the parameter
UNWIRABLE, so a creator parameter annotated `None` *with a default* raised
`ArgumentResolutionError` instead of using it:
def __init__(self, hook: None = None) -> None: ... # -> ArgumentResolutionError
def __init__(self, hook: str = "d") -> None: ... # -> resolves, hook == "d"
`x: None = None` and `x: None` were indistinguishable after parsing — the tell
that `cls()` was dropping state rather than encoding a decision.
Return the degenerate nullable instead: NoneType is a union with zero non-None
members, which is exactly what the union branch would produce for it. The branch
still has to exist — without it NoneType falls through to `isinstance(type_,
type)` and gets looked up in the registry as `arg_type`.
`None` now takes the same two branches as `X | None`: `x: None = None` omits (its
default applies), and bare `x: None` injects None — the annotation's only legal
value, where before it raised. In the return position (`-> None`) the nullability
is unread; only `.arg_type` is consulted, to derive `bound_type`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lesnik512
added a commit
that referenced
this pull request
Jul 17, 2026
Cover the 2.28.0->2.29.0 backlog: the single-path compiled resolver (#334) and its measured perf, the wiring-plan memoization (#326), the three correctness fixes (#340 ContextProvider-via-kwargs default, #321 NoneType default/nullability, #320 validate traverses kwargs=), and the closed provider set under an explicit breaking-change heading (per planning/decisions/2026-07-17-custom-providers-retracted.md, the release notes carry that warning, not the docs). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A creator parameter annotated
Nonewith a default raises instead of using it:SignatureItem.from_type(types_parser.py:21) early-returns a barecls()fortypes.NoneType, discarding both thedefaultit was handed and the nullability the annotation implies. Every other branch threadsdefaultthrough viaresult = {"default": default}.absent_dispositionthen seesdefault is UNSETandis_nullable is False, and classifies the parameterUNWIRABLE.x: None = Noneandx: Nonewere indistinguishable after parsing — the tell thatcls()was dropping state rather than encoding a decision.The fix
Return the degenerate nullable instead of an empty record.
NoneTypeis a union with zero non-Nonemembers, and this is exactly what the union branch below would produce for it:The branch still has to exist: without it,
NoneTypefalls through toisinstance(type_, type)and becomesarg_type=NoneType, which would then be looked up in the registry.Behavior
Nonenow takes the same two branches asX | None, which were already correct:x: None = Nonex: NoneNone)x: str | None = Nonex: str | NoneRow 2 goes beyond the reported defect: bare
x: Nonecurrently errors and will now injectNone. That is the annotation's only legal value, so injecting it is what the type says to do and the error was a false positive.In the return position (
-> None, a void creator) the new nullability is simply unread —factory.py:75consults only.arg_typeto derivebound_type, so a void creator still getsbound_type=Noneexactly as before. Three existingtest_parse_creatorexpectations are updated for the return-position record; no behavior rides on them.Design:
planning/changes/2026-07-14.07-nonetype-param-drops-default.md.Not in scope
The card this came from also flagged that
UnsupportedCreatorParameterErroris raised from two owners —types_parser.py(positional-only) andfactory.py(parameterized generic) — one policy, two homes. Deliberately left alone: it is churn without a forcing function, and the revisit trigger ondecisions/2026-07-14-signatureitem-opacity-superseded.md(a new duplicated raw-field decode idiom) has not fired.Testing
TDD, 5 failing tests written first.
test_signature_item_parser[NoneType]—from_type(None)is nullable.test_nonetype_threads_its_default— parametrized overNone,3,"x". Exercised throughfrom_typerather than a real creator, because onlyNoneis assignable to aNone-annotated parameter, so a non-Nonedefault cannot be spelled in a signature (tycorrectly rejects it).test_nonetype_params_keep_defaults_through_parse_creator— end-to-end through the parser.test_nonetype_param_with_default_uses_the_default/..._without_default_injects_none— resolution-level, the behavior a user actually hits.just test-ci: 386 passed, 100% coverage.just lint-ci: clean.🤖 Generated with Claude Code