-
Notifications
You must be signed in to change notification settings - Fork 2
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
Run mypy on tests #43
Conversation
This allows us to use Pydantic's model APIs directly, instead of going through a `TypeAdapter`. This changeset also enables typechecking on our unit tests. Signed-off-by: William Woodruff <william@trailofbits.com>
Signed-off-by: William Woodruff <william@trailofbits.com>
Signed-off-by: William Woodruff <william@trailofbits.com>
Signed-off-by: William Woodruff <william@trailofbits.com>
Are we sure we want to follow this road? from pydantic import Field, TypeAdapter, RootModel
from typing import Annotated
from pypi_attestations import GitHubPublisher, GitLabPublisher
gh_raw = {"kind": "GitHub", "repository": "foo/bar", "workflow": "publish.yml"}
P_before = Annotated[GitHubPublisher | GitLabPublisher, Field(discriminator="kind")]
P_after = RootModel[Annotated[GitHubPublisher | GitLabPublisher, Field(discriminator='kind')]]
assert isinstance(TypeAdapter(P_before).validate_python(gh_raw), GitHubPublisher) # True
assert isinstance(P_after.model_validate(gh_raw), GitHubPublisher) # False IMO, using |
Yeah, I have mixed feelings about it -- on one hand IMO it makes the types more uniform here, but the need for There are other beneficial changes in this PR, so I'll remove the |
Co-authored-by: dm <alexis.challande@trailofbits.com>
Signed-off-by: William Woodruff <william@trailofbits.com>
Signed-off-by: William Woodruff <william@trailofbits.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This allows us to use Pydantic's model APIs directly, instead of going through aTypeAdapter
.This changeset also enables typechecking on our unit tests.