-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat(python): support TranslationOptions #307
base: main
Are you sure you want to change the base?
Conversation
#[new] | ||
fn __new__(translation_backend: Option<PyTranslationBackend>) -> PyResult<Self> { | ||
Ok(Self(TranslationOptions { | ||
translation_backend: translation_backend.map(|b| b.0), |
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.
Typically, we use the PyWrapper
as_inner()
method to get at the inner value of a wrapped type:
translation_backend: translation_backend.map(|b| b.0), | |
translation_backend: translation_backend.map(|b| b.as_inner()), |
@@ -0,0 +1,45 @@ | |||
from typing import Optional, final | |||
|
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.
@final |
@@ -0,0 +1,45 @@ | |||
from typing import Optional, final |
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.
This file is orphaned. The grpc
and models
directory both need __init__.pyi
files exporting models
, and translation
, respectively.
def from_v1(inner: BackendV1Options) -> "TranslationBackend": ... | ||
@staticmethod | ||
def from_v2(inner: BackendV2Options) -> "TranslationBackend": ... | ||
|
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.
@final |
""" | ||
Options for the V1 translation backend. | ||
""" | ||
|
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.
@final |
- ``from_*``: wrap underlying values as this enum type. | ||
|
||
""" | ||
|
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.
def inner(self) -> Union[BackendV1Options, BackendV2Options]: ... |
@@ -36,6 +36,7 @@ create_init_submodule! { | |||
submodules: [ | |||
"client": client::init_submodule, | |||
"compiler": compiler::init_submodule, | |||
"grpc": grpc::init_submodule, |
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.
I know you are just carrying forward with an existing module and just actually exporting it here, and I know the plan is to add a wrapped type later, but I don't love exporting raw bindings to the API here, and especially exposing them as a "GRPC" module to users.
Other modules get coupled to it because by it's very nature it contains models that requests across the stack need, but the individual models are typically scoped to a single kind of request, so why have them all co-located? It's also ambiguous when you need to pull it in, since our services use a mix of REST and GRPC.
To me, it feels like we're exposing unnecessary implementation details to users and making it more complex than needed to reason about our API and how to use it. translation
is a clean concept within the scope of our product but grpc
is ambiguous and doesn't help users discover useful things about our API.
I could be convinced to re-export the needed GRPC model directly from the translation module, that way it is at least grouped within a concept, reducing the number of imports needed and making it easier to find the needed type with tooling.
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.
Agreed. Went in that direction on a new PR, #308
Closes #306
Closes #281
translate
grpc
module into Python bindingsTODO:
grpc/controller
. Will add that once I know these changes are on the right track