Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Another batch of type annotations #12726

Merged
merged 11 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ disallow_untyped_defs = True
[mypy-synapse.http.server]
disallow_untyped_defs = True

[mypy-synapse.logging._remote]
disallow_untyped_defs = True

[mypy-synapse.logging.context]
disallow_untyped_defs = True

Expand Down
20 changes: 12 additions & 8 deletions synapse/logging/_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
TCP4ClientEndpoint,
TCP6ClientEndpoint,
)
from twisted.internet.interfaces import IPushProducer, IStreamClientEndpoint
from twisted.internet.interfaces import (
IPushProducer,
IReactorTCP,
IStreamClientEndpoint,
)
from twisted.internet.protocol import Factory, Protocol
from twisted.internet.tcp import Connection
from twisted.python.failure import Failure
Expand Down Expand Up @@ -59,14 +63,14 @@ class LogProducer:
_buffer: Deque[logging.LogRecord]
_paused: bool = attr.ib(default=False, init=False)

def pauseProducing(self):
def pauseProducing(self) -> None:
self._paused = True

def stopProducing(self):
def stopProducing(self) -> None:
self._paused = True
self._buffer = deque()

def resumeProducing(self):
def resumeProducing(self) -> None:
# If we're already producing, nothing to do.
self._paused = False

Expand Down Expand Up @@ -102,8 +106,8 @@ def __init__(
host: str,
port: int,
maximum_buffer: int = 1000,
level=logging.NOTSET,
_reactor=None,
level: int = logging.NOTSET,
_reactor: Optional[IReactorTCP] = None,
):
super().__init__(level=level)
self.host = host
Expand All @@ -118,7 +122,7 @@ def __init__(
if _reactor is None:
from twisted.internet import reactor

_reactor = reactor
_reactor = reactor # type: ignore[assignment]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

twisted.internet.reactor is a module that, upon import, removes itself from sys.modules and calls twisted.internet.default.install(). This eventually reinserts twisted.internet.reactor back into sys.modules, but now it points to a reactor instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No wonder mypy is confused.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other spots we do:

from twisted.internet import reactor as _reactor

reactor = cast(ISynapseReactor, _reactor)

🤷 (Could probably just put a cast here instead of an ignore to be consistent.)


try:
ip = ip_address(self.host)
Expand All @@ -139,7 +143,7 @@ def __init__(
self._stopping = False
self._connect()

def close(self):
def close(self) -> None:
self._stopping = True
self._service.stopService()

Expand Down