Skip to content
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

Improve type-checking for _grpchacks #59

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

llucax
Copy link
Contributor

@llucax llucax commented Jun 12, 2024

The ChannelT TypeVar was causing a lot of issues because the types in it would change dynamically depending on which grpc library is installed. This transpired to user code wanting to subclass BaseApiClient which is less than ideal (hacks should be kept internal).

This PR improves this by adding a function to create a channel, which also avoids the need to create a lot of stub grpcio functions, and making ChannelT bound to an AsyncContextManager[Any] instead of the two specific channel classes we use. This interface is enough for the functionality we need from channels.

This way the hacks don't leak to the type system, which was the main issue.

The `ChannelT` `TypeVar` was causing a lot of issues because the types
in it would change dynamically depending on which grpc library is
installed. This transpired to user code wanting to subclass
`BaseApiClient` which is less than ideal (hacks should be kept
internal).

This commit improves this by adding a function to create a channel,
which also avoids the need to create a lot of stub `grpcio` functions,
and making `ChannelT` bound to an `AsyncContextManager[Any]` instead of
the two specific channel classes we use. This interface is enought for
the functionality we need from channels.

This way the hacks don't leak to the type system, which was the main
issue.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
@llucax llucax requested a review from a team as a code owner June 12, 2024 07:56
@llucax llucax self-assigned this Jun 12, 2024
@llucax llucax added this to the v0.5.0 milestone Jun 12, 2024
@github-actions github-actions bot added part:tests Affects the unit, integration and performance (benchmarks) tests part:code Affects the code in general labels Jun 12, 2024
@llucax llucax enabled auto-merge June 12, 2024 07:56
@llucax
Copy link
Contributor Author

llucax commented Jun 12, 2024

Added auto-merge.

@llucax llucax added the cmd:skip-release-notes It is not necessary to update release notes for this PR label Jun 12, 2024
@llucax
Copy link
Contributor Author

llucax commented Jun 12, 2024

Skipping release notes as this affects an unreleased feature.

@llucax llucax added the type:enhancement New feature or enhancement visitble to users label Jun 12, 2024
Copy link

@daniel-zullo-frequenz daniel-zullo-frequenz left a comment

Choose a reason for hiding this comment

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

I only have a question to check for but it might be not entirely related to the current changes. There is a typo in the commit message in case you'd like to fix it in enought.

LGTM, though I'll be waiting for your answer to approve it

@llucax llucax added this pull request to the merge queue Jun 12, 2024
Merged via the queue into frequenz-floss:v0.x.x with commit 49aee99 Jun 12, 2024
15 of 16 checks passed
@llucax llucax deleted the improve-types branch June 12, 2024 10:03
@llucax
Copy link
Contributor Author

llucax commented Jun 12, 2024

Oh, damn, I forgot about the typo in the commit message 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmd:skip-release-notes It is not necessary to update release notes for this PR part:code Affects the code in general part:tests Affects the unit, integration and performance (benchmarks) tests type:enhancement New feature or enhancement visitble to users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants