Skip to content

Commit

Permalink
Remove pytype
Browse files Browse the repository at this point in the history
There are no real advantages over mypy, but at the same time several
downsides such as being slow, producing more false positives, etc.
  • Loading branch information
plamut committed Dec 27, 2021
1 parent ca14426 commit a937a15
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 97 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -29,7 +29,6 @@ pip-log.txt
.nox
.cache
.pytest_cache
.pytype


# Mac
Expand Down
3 changes: 0 additions & 3 deletions google/cloud/pubsub_v1/publisher/client.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/pubsub_v1/publisher/flow_controller.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/pubsub_v1/subscriber/_protocol/leaser.py
Expand Up @@ -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()

Expand Down
Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions google/cloud/pubsub_v1/subscriber/client.py
Expand Up @@ -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,
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion google/cloud/pubsub_v1/subscriber/message.py
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions google/cloud/pubsub_v1/types.py
Expand Up @@ -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.
Expand Down
11 changes: 0 additions & 11 deletions noxfile.py
Expand Up @@ -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"]
Expand All @@ -46,7 +44,6 @@
"lint_setup_py",
"blacken",
"mypy",
"pytype",
# "mypy_samples", # TODO: uncomment when the checks pass
"docs",
]
Expand All @@ -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."""
Expand Down
59 changes: 2 additions & 57 deletions owlbot.py
Expand Up @@ -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.
# ----------------------------------------------------------------------------
Expand Down Expand Up @@ -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>
Expand Down
14 changes: 0 additions & 14 deletions setup.cfg
Expand Up @@ -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

0 comments on commit a937a15

Please sign in to comment.