Repository navigation
fix!: Derive field nullability only from the field-level | None, for every dtype source - #152
Merged
Merged
Conversation
… without parsing it
…r every `dtype` source
FBruzzesi
added a commit
that referenced
this pull request
Nov 22, 2026
…y `dtype` source After the merge of #152, every `dtype` source takes nullability from the field-level type, so `split_field_markers` no longer reports `is_optional` and `merge_field_markers` no longer sets `nullable`. A marker `dtype` on `Literal[..., None]` is now nullable too.
10 of 14 tasks
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.
Summary
A field's nullability now comes only from its field-level type: the
Annotatedlayers, optionally wrapped in one| None, with forward references resolved. A field-levelLiteral[..., None]counts as| None. The rule is the same for everydtypesource: an explicitnullablewins (an explicitNonecounts as unset), otherwise a field-level| Nonemakes the field nullable.UnionTypeStepand theLiteralbranch ofPyTypeStepno longer writenullableinto the metadata. Because they also parse nested types, those writes marked a whole field nullable when only its elements were. Adtypeoverride skipped parsing, so the write never happened and the field's| Nonewas lost.ParserPipeline.parse_into_fieldnow works out nullability itself, after parsing.Closes #141
Closes #142
Supersedes #144, which did the same work on top of #143. This PR applies it to
mainwithout theWithAnySchemamarker changes.Breaking changes
list[T | None],tuple[T | None, ...]andlist[Literal[..., None]]are no longer nullable: only their elements are.T | NoneandLiteral[..., None]with adtypeoverride are now nullable (they used to be non-nullable).nullableany more. A custom step that unwraps a type intoT | Noneno longer makes the field nullable unless it sets{"anyschema": {"nullable": True}}itself. A value a step writes counts as explicit: it beats the field-level| Noneand applies to the whole field.AnySchemaMetadata.nullableis now typedbool | None, whereNonemeans unset.Known limit
With a
dtypeoverride, the type is never parsed. A field-level forward reference that cannot be resolved (an unknown name, a malformed string, or a pipeline withoutForwardRefStep) therefore hides itsNone, and the field comes out non-nullable. Setnullableexplicitly in that case.