Fix type hint errors from Twisted trunk (#16526)
parent
8f35f8148e
commit
3ab861ab9e
|
@ -0,0 +1 @@
|
||||||
|
Improve type hints.
|
|
@ -13,7 +13,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import queue
|
import queue
|
||||||
from typing import BinaryIO, Optional, Union, cast
|
from typing import Any, BinaryIO, Optional, Union, cast
|
||||||
|
|
||||||
from twisted.internet import threads
|
from twisted.internet import threads
|
||||||
from twisted.internet.defer import Deferred
|
from twisted.internet.defer import Deferred
|
||||||
|
@ -58,7 +58,9 @@ class BackgroundFileConsumer:
|
||||||
self._bytes_queue: queue.Queue[Optional[bytes]] = queue.Queue()
|
self._bytes_queue: queue.Queue[Optional[bytes]] = queue.Queue()
|
||||||
|
|
||||||
# Deferred that is resolved when finished writing
|
# Deferred that is resolved when finished writing
|
||||||
self._finished_deferred: Optional[Deferred[None]] = None
|
#
|
||||||
|
# This is really Deferred[None], but mypy doesn't seem to like that.
|
||||||
|
self._finished_deferred: Optional[Deferred[Any]] = None
|
||||||
|
|
||||||
# If the _writer thread throws an exception it gets stored here.
|
# If the _writer thread throws an exception it gets stored here.
|
||||||
self._write_exception: Optional[Exception] = None
|
self._write_exception: Optional[Exception] = None
|
||||||
|
@ -80,9 +82,13 @@ class BackgroundFileConsumer:
|
||||||
self.streaming = streaming
|
self.streaming = streaming
|
||||||
self._finished_deferred = run_in_background(
|
self._finished_deferred = run_in_background(
|
||||||
threads.deferToThreadPool,
|
threads.deferToThreadPool,
|
||||||
self._reactor,
|
# mypy seems to get confused with the chaining of ParamSpec from
|
||||||
self._reactor.getThreadPool(),
|
# run_in_background to deferToThreadPool.
|
||||||
self._writer,
|
#
|
||||||
|
# For Twisted trunk, ignore arg-type; for Twisted release ignore unused-ignore.
|
||||||
|
self._reactor, # type: ignore[arg-type,unused-ignore]
|
||||||
|
self._reactor.getThreadPool(), # type: ignore[arg-type,unused-ignore]
|
||||||
|
self._writer, # type: ignore[arg-type,unused-ignore]
|
||||||
)
|
)
|
||||||
if not streaming:
|
if not streaming:
|
||||||
self._producer.resumeProducing()
|
self._producer.resumeProducing()
|
||||||
|
|
|
@ -156,6 +156,7 @@ class AppServiceHandlerTestCase(unittest.TestCase):
|
||||||
result = self.successResultOf(
|
result = self.successResultOf(
|
||||||
defer.ensureDeferred(self.handler.query_room_alias_exists(room_alias))
|
defer.ensureDeferred(self.handler.query_room_alias_exists(room_alias))
|
||||||
)
|
)
|
||||||
|
assert result is not None
|
||||||
|
|
||||||
self.mock_as_api.query_alias.assert_called_once_with(
|
self.mock_as_api.query_alias.assert_called_once_with(
|
||||||
interested_service, room_alias_str
|
interested_service, room_alias_str
|
||||||
|
|
|
@ -335,7 +335,7 @@ class Deferred__next__Patch:
|
||||||
self._request_number = request_number
|
self._request_number = request_number
|
||||||
self._seen_awaits = seen_awaits
|
self._seen_awaits = seen_awaits
|
||||||
|
|
||||||
self._original_Deferred___next__ = Deferred.__next__
|
self._original_Deferred___next__ = Deferred.__next__ # type: ignore[misc,unused-ignore]
|
||||||
|
|
||||||
# The number of `await`s on `Deferred`s we have seen so far.
|
# The number of `await`s on `Deferred`s we have seen so far.
|
||||||
self.awaits_seen = 0
|
self.awaits_seen = 0
|
||||||
|
|
|
@ -70,7 +70,7 @@ class FederationClientTests(HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def do_request() -> Generator["Deferred[object]", object, object]:
|
def do_request() -> Generator["Deferred[Any]", object, object]:
|
||||||
with LoggingContext("one") as context:
|
with LoggingContext("one") as context:
|
||||||
fetch_d = defer.ensureDeferred(
|
fetch_d = defer.ensureDeferred(
|
||||||
self.cl.get_json("testserv:8008", "foo/bar")
|
self.cl.get_json("testserv:8008", "foo/bar")
|
||||||
|
|
|
@ -30,6 +30,7 @@ from typing import (
|
||||||
Generic,
|
Generic,
|
||||||
Iterable,
|
Iterable,
|
||||||
List,
|
List,
|
||||||
|
Mapping,
|
||||||
NoReturn,
|
NoReturn,
|
||||||
Optional,
|
Optional,
|
||||||
Tuple,
|
Tuple,
|
||||||
|
@ -251,7 +252,7 @@ class TestCase(unittest.TestCase):
|
||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
raise (type(e))(f"Assert error for '.{key}':") from e
|
raise (type(e))(f"Assert error for '.{key}':") from e
|
||||||
|
|
||||||
def assert_dict(self, required: dict, actual: dict) -> None:
|
def assert_dict(self, required: Mapping, actual: Mapping) -> None:
|
||||||
"""Does a partial assert of a dict.
|
"""Does a partial assert of a dict.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
Loading…
Reference in New Issue