Skip to content

Fix pyright compatibility issues with Field defaults in Golden pydantic models #867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kucharzyk-sebastian
Copy link
Contributor

Summary

This PR addresses a compatibility issue when using Pyright static type checking with the Field instantiation from the Pydantic library in Golden model definitions. By explicitly specifying the default keyword in the Field 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:

from deepeval.dataset import Golden

Golden(input="my input")

This resulted in the following Pyright error:

pyright deepeval_x_pyright.py

/home/seku/dev/deepeval/deepeval_x_pyright.py
  /home/seku/dev/deepeval/deepeval_x_pyright.py:4:1 - error: Arguments missing for parameters "actual_output", "expected_output", "context", "retrieval_context", "additional_metadata", "comments", "source_file" (reportCallIssue)
1 error, 0 warnings, 0 information

Solution

To resolve this, default=None was explicitly added to the Field (as suggested in the Pydantic's repository) specifications for optional fields in the Golden 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.

Copy link

vercel bot commented Jul 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
evals-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 5, 2024 0:02am

@penguine-ip
Copy link
Contributor

@kucharzyk-sebastian I see, didn't know this was an issue until now, thank you so much! (will also change other pydantic models apart from goldens for next release)

@penguine-ip penguine-ip merged commit 7fdd5bd into confident-ai:main Jul 8, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants