GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@plamut plamut commented Nov 23, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
plamut added 11 commits November 23, 2021 19:33
@plamut
Add mypy to nox sessions
843e3b9
@plamut
Mark google/cloud package as type-checked
a8ab5d0
@plamut
Ignore types for dependencies lacking type info
3ec491f
@plamut
Fix type annotations in publish flow controller
fd46617
@plamut
Fix type hints in thread-based Batch
7bae7d8
@plamut
Fix type annotations in sequencers
d2790cc
@plamut
Fix type hints in dispatcher
28bcc3e
@plamut
Fix type hints in publisher client
8348dab
@plamut
Fix misc type errors in various modules
57df85c
@plamut
Fix type hints in leaser
ac5937f
@plamut
Fix type annotations in streaming pull manager
07fc275
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 23, 2021
@product-auto-label product-auto-label Bot added the api: pubsub Issues related to the googleapis/python-pubsub API. label Nov 23, 2021
@plamut plamut mentioned this pull request Feb 26, 2026
Make sure type checks pass with mypy as well googleapis/google-cloud-python#15652
Open
4 of 6 tasks
plamut added 2 commits November 24, 2021 19:52
@plamut
Fix gapic timeout hint in older api-core versions
c00330e
google-api-core versions prior to v2.2.2 lack the definition of
_MethodDefault, thus a workaround is needed for that.
@plamut
Remove py.typed marker file
521cac9
The autogenerated code does not pass mypy type checks yet, thus
we should not advertise the package as type-checked.
@plamut
plamut marked this pull request as ready for review November 24, 2021 20:48
@plamut
plamut requested review from a team November 24, 2021 20:48
tseaver
tseaver reviewed Nov 26, 2021
View reviewed changes

@tseaver tseaver left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread google/cloud/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/pubsub_v1/publisher/_sequencer/ordered_sequencer.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/pubsub_v1/publisher/client.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/pubsub_v1/publisher/flow_controller.py
_LOGGER = logging.getLogger(__name__)


MessageType = Type[types.PubsubMessage] # type: ignore # pytype: disable=module-attr

@tseaver tseaver Nov 26, 2021

Copy link
Copy Markdown
Contributor

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.

All reactions

@plamut plamut Nov 26, 2021

Copy link
Copy Markdown
Contributor Author

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.

All reactions
Comment thread google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/pubsub_v1/subscriber/_protocol/leaser.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

plamut added 5 commits November 26, 2021 22:41
@plamut
Replace typing.cast with is not None assertions
3a36ea7
@plamut
Replace batched_commands dict with separate lists
f7a9604
@plamut
Rename variable to avoid false type warnings
d41bbb7
@plamut
Get rid of type cast by using a new variable
1200f06
@plamut
Just ignore the line where type checkers disagree
ffac0ce
@plamut
plamut requested a review from tseaver November 26, 2021 21:59
@plamut

plamut commented Nov 26, 2021

Copy link
Copy Markdown
Contributor Author

A few trivial errors, will fix the checks tomorrow.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tseaver
tseaver approved these changes Nov 27, 2021
View reviewed changes
plamut added 2 commits November 27, 2021 09:09
@plamut
Remove unused imports
38eaa97
@plamut
Replace type casts with is not None assertions
41be7cb
@plamut
Cover missing dispatcher case after refactoring
854c6fe
@plamut
plamut requested a review from tseaver November 27, 2021 09:00
@plamut

plamut commented Nov 27, 2021

Copy link
Copy Markdown
Contributor Author

@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).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tseaver
tseaver approved these changes Nov 30, 2021
View reviewed changes
@plamut
plamut merged commit 8f32dd4 into googleapis:main Nov 30, 2021
@plamut
plamut deleted the iss-536 branch November 30, 2021 14:59
@parthea parthea mentioned this pull request Dec 2, 2021
DO NOT MERGE: revert local changes to mypy #544
Closed
@plamut
plamut restored the iss-536 branch December 17, 2021 19:04
@blunderbuss-gcf blunderbuss-gcf Bot assigned abbrowne126 Feb 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

1 more reviewer
@tseaver 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.

Assignees

@abbrowne126 abbrowne126

Labels

api: pubsub Issues related to the googleapis/python-pubsub API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

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.

3 participants

@plamut @tseaver @abbrowne126
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.