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

Commit 9ec3da0

Browse files
authored
Bump mypy-zope & mypy. (#16188)
1 parent 001fc7b commit 9ec3da0

39 files changed

+180
-161
lines changed

changelog.d/16188.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve type hints.

poetry.lock

Lines changed: 36 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

synapse/_scripts/synapse_port_db.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,10 @@ def r(
482482
do_backward[0] = False
483483

484484
if forward_rows or backward_rows:
485-
headers = [column[0] for column in txn.description]
485+
assert txn.description is not None
486+
headers: Optional[List[str]] = [
487+
column[0] for column in txn.description
488+
]
486489
else:
487490
headers = None
488491

@@ -544,6 +547,7 @@ async def handle_search_table(
544547
def r(txn: LoggingTransaction) -> Tuple[List[str], List[Tuple]]:
545548
txn.execute(select, (forward_chunk, self.batch_size))
546549
rows = txn.fetchall()
550+
assert txn.description is not None
547551
headers = [column[0] for column in txn.description]
548552

549553
return headers, rows
@@ -919,7 +923,8 @@ async def _setup_sent_transactions(self) -> Tuple[int, int, int]:
919923
def r(txn: LoggingTransaction) -> Tuple[List[str], List[Tuple]]:
920924
txn.execute(select)
921925
rows = txn.fetchall()
922-
headers: List[str] = [column[0] for column in txn.description]
926+
assert txn.description is not None
927+
headers = [column[0] for column in txn.description]
923928

924929
ts_ind = headers.index("ts")
925930

synapse/logging/opentracing.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -910,10 +910,10 @@ def _wrapping_logic(func: Callable[P, R], *args: P.args, **kwargs: P.kwargs) ->
910910
async def _wrapper(
911911
*args: P.args, **kwargs: P.kwargs
912912
) -> Any: # Return type is RInner
913-
with wrapping_logic(func, *args, **kwargs):
914-
# type-ignore: func() returns R, but mypy doesn't know that R is
915-
# Awaitable here.
916-
return await func(*args, **kwargs) # type: ignore[misc]
913+
# type-ignore: func() returns R, but mypy doesn't know that R is
914+
# Awaitable here.
915+
with wrapping_logic(func, *args, **kwargs): # type: ignore[arg-type]
916+
return await func(*args, **kwargs)
917917

918918
else:
919919
# The other case here handles sync functions including those decorated with
@@ -980,8 +980,7 @@ def trace_with_opname(
980980
See the module's doc string for usage examples.
981981
"""
982982

983-
# type-ignore: mypy bug, see https://github.com/python/mypy/issues/12909
984-
@contextlib.contextmanager # type: ignore[arg-type]
983+
@contextlib.contextmanager
985984
def _wrapping_logic(
986985
func: Callable[P, R], *args: P.args, **kwargs: P.kwargs
987986
) -> Generator[None, None, None]:
@@ -1024,8 +1023,7 @@ def tag_args(func: Callable[P, R]) -> Callable[P, R]:
10241023
if not opentracing:
10251024
return func
10261025

1027-
# type-ignore: mypy bug, see https://github.com/python/mypy/issues/12909
1028-
@contextlib.contextmanager # type: ignore[arg-type]
1026+
@contextlib.contextmanager
10291027
def _wrapping_logic(
10301028
func: Callable[P, R], *args: P.args, **kwargs: P.kwargs
10311029
) -> Generator[None, None, None]:

synapse/storage/database.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
Iterator,
3232
List,
3333
Optional,
34+
Sequence,
3435
Tuple,
3536
Type,
3637
TypeVar,
@@ -358,7 +359,21 @@ def rowcount(self) -> int:
358359
return self.txn.rowcount
359360

360361
@property
361-
def description(self) -> Any:
362+
def description(
363+
self,
364+
) -> Optional[
365+
Sequence[
366+
Tuple[
367+
str,
368+
Optional[Any],
369+
Optional[int],
370+
Optional[int],
371+
Optional[int],
372+
Optional[int],
373+
Optional[int],
374+
]
375+
]
376+
]:
362377
return self.txn.description
363378

364379
def execute_batch(self, sql: str, args: Iterable[Iterable[Any]]) -> None:

synapse/util/check_dependencies.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def dependencies(self) -> Iterable[str]:
5151

5252

5353
DEV_EXTRAS = {"lint", "mypy", "test", "dev"}
54-
RUNTIME_EXTRAS = (
55-
set(metadata.metadata(DISTRIBUTION_NAME).get_all("Provides-Extra")) - DEV_EXTRAS
56-
)
54+
ALL_EXTRAS = metadata.metadata(DISTRIBUTION_NAME).get_all("Provides-Extra")
55+
assert ALL_EXTRAS is not None
56+
RUNTIME_EXTRAS = set(ALL_EXTRAS) - DEV_EXTRAS
5757
VERSION = metadata.version(DISTRIBUTION_NAME)
5858

5959

tests/appservice/test_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def get_json(
9696
)
9797

9898
# We assign to a method, which mypy doesn't like.
99-
self.api.get_json = Mock(side_effect=get_json) # type: ignore[assignment]
99+
self.api.get_json = Mock(side_effect=get_json) # type: ignore[method-assign]
100100

101101
result = self.get_success(
102102
self.api.query_3pe(self.service, "user", PROTOCOL, {b"some": [b"field"]})
@@ -168,7 +168,7 @@ async def get_json(
168168
)
169169

170170
# We assign to a method, which mypy doesn't like.
171-
self.api.get_json = Mock(side_effect=get_json) # type: ignore[assignment]
171+
self.api.get_json = Mock(side_effect=get_json) # type: ignore[method-assign]
172172

173173
result = self.get_success(
174174
self.api.query_3pe(self.service, "user", PROTOCOL, {b"some": [b"field"]})
@@ -215,7 +215,7 @@ async def post_json_get_json(
215215
return RESPONSE
216216

217217
# We assign to a method, which mypy doesn't like.
218-
self.api.post_json_get_json = Mock(side_effect=post_json_get_json) # type: ignore[assignment]
218+
self.api.post_json_get_json = Mock(side_effect=post_json_get_json) # type: ignore[method-assign]
219219

220220
MISSING_KEYS = [
221221
# Known user, known device, missing algorithm.

tests/federation/test_complexity.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_complexity_simple(self) -> None:
5757
async def get_current_state_event_counts(room_id: str) -> int:
5858
return int(500 * 1.23)
5959

60-
store.get_current_state_event_counts = get_current_state_event_counts # type: ignore[assignment]
60+
store.get_current_state_event_counts = get_current_state_event_counts # type: ignore[method-assign]
6161

6262
# Get the room complexity again -- make sure it's our artificial value
6363
channel = self.make_signed_federation_request(
@@ -74,8 +74,8 @@ def test_join_too_large(self) -> None:
7474
fed_transport = self.hs.get_federation_transport_client()
7575

7676
# Mock out some things, because we don't want to test the whole join
77-
fed_transport.client.get_json = AsyncMock(return_value={"v1": 9999}) # type: ignore[assignment]
78-
handler.federation_handler.do_invite_join = AsyncMock( # type: ignore[assignment]
77+
fed_transport.client.get_json = AsyncMock(return_value={"v1": 9999}) # type: ignore[method-assign]
78+
handler.federation_handler.do_invite_join = AsyncMock( # type: ignore[method-assign]
7979
return_value=("", 1)
8080
)
8181

@@ -105,8 +105,8 @@ def test_join_too_large_admin(self) -> None:
105105
fed_transport = self.hs.get_federation_transport_client()
106106

107107
# Mock out some things, because we don't want to test the whole join
108-
fed_transport.client.get_json = AsyncMock(return_value={"v1": 9999}) # type: ignore[assignment]
109-
handler.federation_handler.do_invite_join = AsyncMock( # type: ignore[assignment]
108+
fed_transport.client.get_json = AsyncMock(return_value={"v1": 9999}) # type: ignore[method-assign]
109+
handler.federation_handler.do_invite_join = AsyncMock( # type: ignore[method-assign]
110110
return_value=("", 1)
111111
)
112112

@@ -142,16 +142,16 @@ def test_join_too_large_once_joined(self) -> None:
142142
fed_transport = self.hs.get_federation_transport_client()
143143

144144
# Mock out some things, because we don't want to test the whole join
145-
fed_transport.client.get_json = AsyncMock(return_value=None) # type: ignore[assignment]
146-
handler.federation_handler.do_invite_join = AsyncMock( # type: ignore[assignment]
145+
fed_transport.client.get_json = AsyncMock(return_value=None) # type: ignore[method-assign]
146+
handler.federation_handler.do_invite_join = AsyncMock( # type: ignore[method-assign]
147147
return_value=("", 1)
148148
)
149149

150150
# Artificially raise the complexity
151151
async def get_current_state_event_counts(room_id: str) -> int:
152152
return 600
153153

154-
self.hs.get_datastores().main.get_current_state_event_counts = get_current_state_event_counts # type: ignore[assignment]
154+
self.hs.get_datastores().main.get_current_state_event_counts = get_current_state_event_counts # type: ignore[method-assign]
155155

156156
d = handler._remote_join(
157157
create_requester(u1),
@@ -199,8 +199,8 @@ def test_join_too_large_no_admin(self) -> None:
199199
fed_transport = self.hs.get_federation_transport_client()
200200

201201
# Mock out some things, because we don't want to test the whole join
202-
fed_transport.client.get_json = AsyncMock(return_value={"v1": 9999}) # type: ignore[assignment]
203-
handler.federation_handler.do_invite_join = AsyncMock( # type: ignore[assignment]
202+
fed_transport.client.get_json = AsyncMock(return_value={"v1": 9999}) # type: ignore[method-assign]
203+
handler.federation_handler.do_invite_join = AsyncMock( # type: ignore[method-assign]
204204
return_value=("", 1)
205205
)
206206

@@ -229,8 +229,8 @@ def test_join_too_large_admin(self) -> None:
229229
fed_transport = self.hs.get_federation_transport_client()
230230

231231
# Mock out some things, because we don't want to test the whole join
232-
fed_transport.client.get_json = AsyncMock(return_value={"v1": 9999}) # type: ignore[assignment]
233-
handler.federation_handler.do_invite_join = AsyncMock( # type: ignore[assignment]
232+
fed_transport.client.get_json = AsyncMock(return_value={"v1": 9999}) # type: ignore[method-assign]
233+
handler.federation_handler.do_invite_join = AsyncMock( # type: ignore[method-assign]
234234
return_value=("", 1)
235235
)
236236

tests/federation/test_federation_catch_up.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
5050
# This mock is crucial for destination_rooms to be populated.
5151
# TODO: this seems to no longer be the case---tests pass with this mock
5252
# commented out.
53-
state_storage_controller.get_current_hosts_in_room = AsyncMock( # type: ignore[assignment]
53+
state_storage_controller.get_current_hosts_in_room = AsyncMock( # type: ignore[method-assign]
5454
return_value={"test", "host2"}
5555
)
5656

@@ -436,7 +436,7 @@ def test_catch_up_on_synapse_startup(self) -> None:
436436
def wake_destination_track(destination: str) -> None:
437437
woken.add(destination)
438438

439-
self.federation_sender.wake_destination = wake_destination_track # type: ignore[assignment]
439+
self.federation_sender.wake_destination = wake_destination_track # type: ignore[method-assign]
440440

441441
# We wait quite long so that all dests can be woken up, since there is a delay
442442
# between them.

tests/federation/test_federation_sender.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
4747
federation_transport_client=self.federation_transport_client,
4848
)
4949

50-
hs.get_storage_controllers().state.get_current_hosts_in_room = AsyncMock( # type: ignore[assignment]
50+
hs.get_storage_controllers().state.get_current_hosts_in_room = AsyncMock( # type: ignore[method-assign]
5151
return_value={"test", "host2"}
5252
)
5353

54-
hs.get_storage_controllers().state.get_current_hosts_in_room_or_partial_state_approximation = ( # type: ignore[assignment]
54+
hs.get_storage_controllers().state.get_current_hosts_in_room_or_partial_state_approximation = ( # type: ignore[method-assign]
5555
hs.get_storage_controllers().state.get_current_hosts_in_room
5656
)
5757

0 commit comments

Comments
 (0)