Uh oh!
There was an error while loading. Please reload this page.
process: make sure type annoations pass with mypy - #542
Conversation
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.
tseaver
left a comment
There was a problem hiding this comment.
Overall, I'd like to see us using only one typing checker, and I think 'mytype' is the consensus favorite.
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.
I don't understand the type: ignore here, and I think this may be a misuse of Type[].
There was a problem hiding this comment.
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)
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.
plamut
commented
Nov 26, 2021
A few trivial errors, will fix the checks tomorrow. |
plamut
commented
Nov 27, 2021
@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 |
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:
mypyreports 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 addsMarker file removed for the time being.py.typedmarker file, but we might want to postpone this addition until the generated code is error-free._TimeoutTypeare defined in multiple places. We should probably extract the definition to a single central place within the library.PR checklist: