Fix pyright compatibility issues with Field defaults in Golden pydantic models #867
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
This PR addresses a compatibility issue when using Pyright static type checking with the
Field
instantiation from the Pydantic library inGolden
model definitions. By explicitly specifying thedefault
keyword in theField
instantiation, we ensure Pyright doesn't throw errors for users who employ Pyright alongside Golden models.Issue Encountered
When attempting to instantiate a
Golden
object with minimal arguments in a project using Pyright, the type checker raised errors about missing arguments that should be optional. Here's the code snippet and the error message encountered:This resulted in the following Pyright error:
Solution
To resolve this,
default=None
was explicitly added to theField
(as suggested in the Pydantic's repository) specifications for optional fields in theGolden
Pydantic models. This modification clears the Pyright errors and makes the field defaults explicit, adhering to the updated practices recommended for Pydantic.Expected Benefits
Compatibility: Ensures Goldens' compatibility with Pyright, facilitating development without static type-checking interruptions.
Usability: Assures that all developers using the Golden model with Pyright experience no interruptions or false positives from type checking.
Clarity and Maintenance: Improves the maintainability and clarity of the code by explicitly defining optional parameters as such.