-
Notifications
You must be signed in to change notification settings - Fork 69
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
fix: use correct typing for retries #1026
Conversation
@@ -22,6 +22,8 @@ from google.auth.transport.grpc import SslCredentials # type: ignore | |||
from google.auth.exceptions import MutualTLSChannelError # type: ignore | |||
from google.oauth2 import service_account # type: ignore | |||
|
|||
OptionalRetry = Union[retries.Retry, object] |
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.
Wouldn't this be equivalent to Any
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.
I had to do some gymnastics to get a default sentinel type checkable in the BQ library:
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'm not sure. I do know that gapic_v1.method.DEFAULT_RETRY
is just an instance of object
.
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.
Right. That's what I mean. object
is a very generic type. Basically everything is object
, so union with that is basically Any
.
Would folks be open to making a more explicit type for the default sentinel like we did in BQ?
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.
To test if it is equivalent to Any
, we could try passing a string as a retry argument. It ideally should fail type checks.
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 believe DEFAULT_RETRY
is a specific object used as a canary.
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.
If we update api-core
to provide a different type for the marker object, then we can tweak the templates to use it -- otherwise, the typechecker hates that we are using that specific object as the default when we say the parameter is a retries.Retry
.
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.
Okay. Well I suspect this makes the type checker happy with any object, which isn't what we want. Did you see the pattern I used in google-cloud-bigquery
? That pattern uses the fact that enums can be type checked to look for a specific object.
f604149
to
4ae06f1
Compare
fix: import 'ClientOptions' class correctly
Closes #1024
Closes #1025