Enforce Optional[T] typing for None-defaulted Pydantic fields#3209
Open
jeffreyksmithjr wants to merge 1 commit intonebari-dev:mainfrom
Open
Enforce Optional[T] typing for None-defaulted Pydantic fields#3209jeffreyksmithjr wants to merge 1 commit intonebari-dev:mainfrom
jeffreyksmithjr wants to merge 1 commit intonebari-dev:mainfrom
Conversation
Fix two fields that default to None without including None in their type annotation. Add a test that introspects all nebari Pydantic models at runtime and fails if any field defaults to None without an explicit Optional (or Union with None) in its annotation.
18 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.
Reference Issues or PRs
See also: nebari-dev/nebari-docs#615 (companion docs PR)
What does this implement/fix?
Put a
xin the boxes that applyDocumentation
Testing
How to test this PR?
Run the new enforcement test:
The test dynamically imports all modules under nebari and _nebari, collects
every Pydantic BaseModel subclass, and verifies that any field defaulting to
None includes NoneType in its resolved annotation. It handles Optional,
Union, T | None, and Annotated wrappers.
Any other comments?
Two existing violations were fixed:
GCPClusterInputVars.node_group_image_typeinstages/infrastructure/__init__.pyStorage.typeinstages/kubernetes_services/__init__.pyBoth already had
Optionalimported in their respective files.