-
Notifications
You must be signed in to change notification settings - Fork 207
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: refactor client classes for safer type checking #552
Conversation
c1e59dd
to
353be0a
Compare
353be0a
to
a937a15
Compare
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.
Looks a lot cleaner! A couple of questions.
There are no real advantages over mypy, but at the same time several downsides such as being slow, producing more false positives, etc.
a937a15
to
4457779
Compare
Getting a few mypy errors on the samples
|
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 other than the failing samples checks. Thanks for adding the api
property back.
owlbot.py
Outdated
@@ -467,12 +412,12 @@ def mypy(session): | |||
# ---------------------------------------------------------------------------- | |||
s.replace( | |||
"noxfile.py", | |||
r'"pytype",', | |||
r' "mypy",', | |||
'\g<0>\n # "mypy_samples", # TODO: uncomment when the checks pass', |
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.
Out-of-date comment?
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.
Indeed, will remove it so that owlbot will not add it back.
This used to pass (IIRC), will see what changes are needed to bring it back to green state. |
@tswast I confused the type-check errors with BigQuery, they were only fixed there. There are two classes of errors reported by Pub/Sub samples type check:
While the latter can be solved by adding the missing annotations to We would have to avoid dynamically injected content, perhaps by some sort of a preprocessor that would copy/paste the generated types directly into cc: @pradn Edit: I'd say this gives us a good base for future iterations, while preserving the improvements accumulated so far. |
I think we should definitely annotate the missing methods in
That is probably the right long-term solution. That said, it appears there are less than a dozen instances of "Module has no attribute" in the https://github.com/googleapis/python-pubsub/blob/main/google/pubsub_v1/types/__init__.py The latter does have a few manual classes, but for the proto message types seems to just be redirecting (way too many in my opinion, there's no point in defining aliases for the shared types for example) various protobuf modules into the same namespace. |
Re: third option, since we haven't added a |
Towards #536.
This PR is based on #551, it addresses the false positives
mypy
produces due to the fact that it cannot know that most of the generated methods are dynamically injected into the hand-written client wrapper classes.#551 should likely be merged first, as this change is somewhat more risky, and we want to have it in its own commit to make the rollback easier and smaller, should that be necessary.