Skip to content

Python: Adjust the builder's contained type to be covariant #797

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

Merged

Conversation

AurisAudentis
Copy link
Contributor

The problem

As of currently, the grafana_foundation_sdk does not pass typechecking in its example.

This is because the with_target function expects a cogbuilder.Builder[cogvariants.Dataquery] type to be passed, but the prometheus query returns a Dataquery, which inherits from cogbuilder.Builder[prometheus.Dataquery].

This doesn't type check, because they are not the same type, and the generic type is not marked as covariant.

Solution

Given the implementation of build, I believe the type is in practice covariant.
Marking it as such fixes the type checking of the dashboard.

@AurisAudentis AurisAudentis requested a review from a team as a code owner April 18, 2025 14:55
@CLAassistant
Copy link

CLAassistant commented Apr 18, 2025

CLA assistant check
All committers have signed the CLA.

@AurisAudentis AurisAudentis changed the title bug: Adjust the builder's contained type to be covariant Python: Adjust the builder's contained type to be covariant Apr 18, 2025
Copy link
Member

@K-Phoen K-Phoen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing and submitting a PR 🚀

@K-Phoen K-Phoen merged commit b2dd4c8 into grafana:main Apr 26, 2025
9 of 10 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.

3 participants