From a937a1522b18750af418660bc5fe7278bcc97d22 Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Mon, 27 Dec 2021 09:18:20 +0200 Subject: [PATCH] Remove pytype There are no real advantages over mypy, but at the same time several downsides such as being slow, producing more false positives, etc. --- .gitignore | 1 - google/cloud/pubsub_v1/publisher/client.py | 3 - .../pubsub_v1/publisher/flow_controller.py | 2 +- .../pubsub_v1/subscriber/_protocol/leaser.py | 2 +- .../_protocol/streaming_pull_manager.py | 3 - google/cloud/pubsub_v1/subscriber/client.py | 3 - google/cloud/pubsub_v1/subscriber/message.py | 2 +- google/cloud/pubsub_v1/types.py | 2 - noxfile.py | 11 ---- owlbot.py | 59 +------------------ setup.cfg | 14 ----- 11 files changed, 5 insertions(+), 97 deletions(-) diff --git a/.gitignore b/.gitignore index 99c3a1444..b4243ced7 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,6 @@ pip-log.txt .nox .cache .pytest_cache -.pytype # Mac diff --git a/google/cloud/pubsub_v1/publisher/client.py b/google/cloud/pubsub_v1/publisher/client.py index 0eafb194c..b60b5aba5 100644 --- a/google/cloud/pubsub_v1/publisher/client.py +++ b/google/cloud/pubsub_v1/publisher/client.py @@ -200,15 +200,12 @@ def _get_or_create_sequencer(self, topic: str, ordering_key: str) -> SequencerTy sequencer_key = (topic, ordering_key) sequencer = self._sequencers.get(sequencer_key) if sequencer is None: - # Disable pytype false positive... - # pytype: disable=wrong-arg-types if ordering_key == "": sequencer = unordered_sequencer.UnorderedSequencer(self, topic) else: sequencer = ordered_sequencer.OrderedSequencer( self, topic, ordering_key ) - # pytype: enable=wrong-arg-types self._sequencers[sequencer_key] = sequencer return sequencer diff --git a/google/cloud/pubsub_v1/publisher/flow_controller.py b/google/cloud/pubsub_v1/publisher/flow_controller.py index 3c0558fe5..baf6ba8ff 100644 --- a/google/cloud/pubsub_v1/publisher/flow_controller.py +++ b/google/cloud/pubsub_v1/publisher/flow_controller.py @@ -25,7 +25,7 @@ _LOGGER = logging.getLogger(__name__) -MessageType = Type[types.PubsubMessage] # type: ignore # pytype: disable=module-attr +MessageType = Type[types.PubsubMessage] # type: ignore class _QuantityReservation: diff --git a/google/cloud/pubsub_v1/subscriber/_protocol/leaser.py b/google/cloud/pubsub_v1/subscriber/_protocol/leaser.py index 7cd9317e6..bfa1b5a49 100644 --- a/google/cloud/pubsub_v1/subscriber/_protocol/leaser.py +++ b/google/cloud/pubsub_v1/subscriber/_protocol/leaser.py @@ -76,7 +76,7 @@ def message_count(self) -> int: return len(self._leased_messages) @property - def ack_ids(self) -> KeysView[str]: # pytype: disable=invalid-annotation + def ack_ids(self) -> KeysView[str]: """The ack IDs of all leased messages.""" return self._leased_messages.keys() diff --git a/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py b/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py index ffb9c7814..d207718fc 100644 --- a/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py +++ b/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py @@ -548,14 +548,11 @@ def open( # Create references to threads assert self._scheduler is not None - # pytype: disable=wrong-arg-types - # (pytype incorrectly complains about "self" not being the right argument type) scheduler_queue = self._scheduler.queue self._dispatcher = dispatcher.Dispatcher(self, scheduler_queue) self._consumer = bidi.BackgroundConsumer(self._rpc, self._on_response) self._leaser = leaser.Leaser(self) self._heartbeater = heartbeater.Heartbeater(self) - # pytype: enable=wrong-arg-types # Start the thread to pass the requests. self._dispatcher.start() diff --git a/google/cloud/pubsub_v1/subscriber/client.py b/google/cloud/pubsub_v1/subscriber/client.py index 9886b4f74..637e56a33 100644 --- a/google/cloud/pubsub_v1/subscriber/client.py +++ b/google/cloud/pubsub_v1/subscriber/client.py @@ -232,8 +232,6 @@ def callback(message): """ flow_control = types.FlowControl(*flow_control) - # Disable pytype false positive... - # pytype: disable=wrong-arg-types manager = streaming_pull_manager.StreamingPullManager( self, subscription, @@ -242,7 +240,6 @@ def callback(message): use_legacy_flow_control=use_legacy_flow_control, await_callbacks_on_shutdown=await_callbacks_on_shutdown, ) - # pytype: enable=wrong-arg-types future = futures.StreamingPullFuture(manager) diff --git a/google/cloud/pubsub_v1/subscriber/message.py b/google/cloud/pubsub_v1/subscriber/message.py index 5bd84e9ad..2d72bba57 100644 --- a/google/cloud/pubsub_v1/subscriber/message.py +++ b/google/cloud/pubsub_v1/subscriber/message.py @@ -81,7 +81,7 @@ class Message(object): The time that this message was originally published. """ - def __init__( # pytype: disable=module-attr + def __init__( self, message: "types.PubsubMessage._meta._pb", # type: ignore ack_id: str, diff --git a/google/cloud/pubsub_v1/types.py b/google/cloud/pubsub_v1/types.py index 62dffcfc3..e843a6da9 100644 --- a/google/cloud/pubsub_v1/types.py +++ b/google/cloud/pubsub_v1/types.py @@ -127,13 +127,11 @@ class PublisherOptions(NamedTuple): "an instance of :class:`google.api_core.retry.Retry`." ) - # pytype: disable=invalid-annotation timeout: "OptionalTimeout" = gapic_v1.method.DEFAULT # use api_core default ( "Timeout settings for message publishing by the client. It should be " "compatible with :class:`~.pubsub_v1.types.TimeoutType`." ) - # pytype: enable=invalid-annotation # Define the type class and default values for flow control settings. diff --git a/noxfile.py b/noxfile.py index b7f9f2e94..1f0f20bbd 100644 --- a/noxfile.py +++ b/noxfile.py @@ -28,8 +28,6 @@ BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] MYPY_VERSION = "mypy==0.910" -PYTYPE_VERSION = "pytype==2021.4.9" - DEFAULT_PYTHON_VERSION = "3.8" SYSTEM_TEST_PYTHON_VERSIONS = ["3.10"] @@ -46,7 +44,6 @@ "lint_setup_py", "blacken", "mypy", - "pytype", # "mypy_samples", # TODO: uncomment when the checks pass "docs", ] @@ -71,14 +68,6 @@ def mypy(session): session.run("mypy", "google/cloud") -@nox.session(python=DEFAULT_PYTHON_VERSION) -def pytype(session): - """Run type checks.""" - session.install("-e", ".[all]") - session.install(PYTYPE_VERSION) - session.run("pytype") - - @nox.session(python=DEFAULT_PYTHON_VERSION) def mypy_samples(session): """Run type checks with mypy.""" diff --git a/owlbot.py b/owlbot.py index 3f1247aa2..daa1f7111 100644 --- a/owlbot.py +++ b/owlbot.py @@ -364,61 +364,6 @@ # ---------------------------------------------------------------------------- python.py_samples() -# ---------------------------------------------------------------------------- -# pytype-related changes -# ---------------------------------------------------------------------------- - -# Add .pytype to .gitignore -s.replace(".gitignore", r"\.pytest_cache", "\g<0>\n.pytype") - -# Add pytype config to setup.cfg -s.replace( - "setup.cfg", - r"universal = 1", - textwrap.dedent( - """ \g<0> - - [pytype] - python_version = 3.8 - inputs = - google/cloud/ - exclude = - tests/ - google/pubsub_v1/ # generated code - output = .pytype/ - disable = - # There's some issue with finding some pyi files, thus disabling. - # The issue https://github.com/google/pytype/issues/150 is closed, but the - # error still occurs for some reason. - pyi-error""" - ), -) - -# Add pytype session to noxfile.py -s.replace( - "noxfile.py", - r"BLACK_PATHS = \[.*?\]", - '\g<0>\nPYTYPE_VERSION = "pytype==2021.4.9"\n', -) -s.replace( - "noxfile.py", r'"blacken",', '\g<0>\n "pytype",', -) -s.replace( - "noxfile.py", - r"nox\.options\.error_on_missing_interpreters = True", - textwrap.dedent( - ''' \g<0> - - - @nox.session(python=DEFAULT_PYTHON_VERSION) - def pytype(session): - """Run type checks.""" - session.install("-e", ".[all]") - session.install(PYTYPE_VERSION) - session.run("pytype")''' - ), -) - # ---------------------------------------------------------------------------- # Add mypy nox session. # ---------------------------------------------------------------------------- @@ -460,12 +405,12 @@ def mypy(session): # ---------------------------------------------------------------------------- s.replace( "noxfile.py", - r'"pytype",', + r' "mypy",', '\g<0>\n # "mypy_samples", # TODO: uncomment when the checks pass', ) s.replace( "noxfile.py", - r'session\.run\("pytype"\)', + r'session\.run\("mypy", "google/cloud"\)', textwrap.dedent( ''' \g<0> diff --git a/setup.cfg b/setup.cfg index a79cb6a60..c3a2b39f6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,17 +17,3 @@ # Generated by synthtool. DO NOT EDIT! [bdist_wheel] universal = 1 - -[pytype] -python_version = 3.8 -inputs = - google/cloud/ -exclude = - tests/ - google/pubsub_v1/ # generated code -output = .pytype/ -disable = - # There's some issue with finding some pyi files, thus disabling. - # The issue https://github.com/google/pytype/issues/150 is closed, but the - # error still occurs for some reason. - pyi-error