GeezerVison is showing github.com — process: make sure type annoations pass with mypy by plamut · Pull Request #542 · googleapis/python-pubsub
This repository was archived by the owner on Oct 13, 2026. It is now read-only.
Conversation
plamut
commented
Nov 23, 2021
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Towards googleapis/google-cloud-python#15652.
This is a draft PR. The new noxfile check, mypy, passes locally, but there are still a few things to consider:
- The generated code is omitted from type checks, because
mypy reports several errors for it
(will be done separately, since it's currently blocked by Generated code for Pub/Sub does not pass type checks with mypy gapic-generator-python#1092 )
-
The PR adds py.typed marker file, but we might want to postpone this addition until the generated code is error-free. Marker file removed for the time being.
- Some type aliases such as
_TimeoutType are defined in multiple places. We should probably extract the definition to a single central place within the library.
PR checklist:
- Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
- Ensure the tests and linter pass
- Code coverage does not decrease (if any source code was changed)
- Appropriate docs were updated (if necessary)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
google-api-core versions prior to v2.2.2 lack the definition of
_MethodDefault, thus a workaround is needed for that.
The autogenerated code does not pass mypy type checks yet, thus
we should not advertise the package as type-checked.
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.
Overall, I'd like to see us using only one typing checker, and I think 'mytype' is the consensus favorite.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
MessageType = Type[types.PubsubMessage] # type: ignore # pytype: disable=module-attr
|
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 don't understand the type: ignore here, and I think this may be a misuse of Type[].
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
The ignore here is needed, because PubsubMessage is dynamically injected into google/cloud/pubsub_v1/types.py and both type checkers think it does not exist. The alias was created to not repeat the same ignore comment in every line where message is a method parameter.
Using a plain types.PubsubMessage in the alias results in mypy complaining that variable MessageType is not valid as a type. Using Type[...] works around that.
(alternatives welcome, especially if they are canonical)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
A few trivial errors, will fix the checks tomorrow.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@tseaver The required changes turned out to be more than just a few trivial lines, thus please take another look when you manage.
It's mostly just getting rid of cast() for Optional types, and one extra case in Dispatcher had to be covered after splitting batch_commands into separate lists (coverage complaint).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
1 more reviewer
tseaver
tseaver approved these changes
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Labels
api: pubsub
Issues related to the googleapis/python-pubsub API.
cla: yes
This human has signed the Contributor License Agreement.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|