From 1438a34f983fc16fdd8c804231e877b18f1a73ef Mon Sep 17 00:00:00 2001 From: David Robertson Date: Wed, 15 Jun 2022 10:18:10 +0100 Subject: [PATCH 1/3] Mark state_before as StateMap[str] There is a three-branch if/elif/else. Mypy deduces that this variable - is a Dict, according to the first branch - is a Dict[Tuple[str, str], str] according to the second branch - and prior to [1], mypy was unable to deduce anything from the third branch, because `state_before` is written to with the result of `successResultOf`. Now that `successResultOf` is annotated, mypy is alarmed that we try to assign a Mapping to a Dict. Fix this by telling mypy it was a mapping all along. [1]: https://github.com/twisted/twisted/pull/1736/commits/3f8c49816bc34f74167ea3e0579f0d5dde25aeec, --- tests/state/test_v2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/state/test_v2.py b/tests/state/test_v2.py index 78b83d97b61a..2e3f2318d9bf 100644 --- a/tests/state/test_v2.py +++ b/tests/state/test_v2.py @@ -495,6 +495,7 @@ def do_check( prev_events = list(graph[node_id]) + state_before: StateMap[str] if len(prev_events) == 0: state_before = {} elif len(prev_events) == 1: From 0b2829337e072797d8b907cad30c1fa651c3d0a5 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Wed, 15 Jun 2022 10:27:22 +0100 Subject: [PATCH 2/3] Use get_success in tests handling `@cached` funcs As of [1], successResultOf is typed. It expects a Deferred. We give it the return type `T` of asynchronous function which is decorated by @cached. I.e. `T` is the type of `@cached(func)(arg, ...)`. AFAICS `T` is a `DeferredCacheDescriptor` which sounds like something that ought to produce `Deferred`s... but again, it's mysterious murky magic. Use `get_success` instead, which seems to be the done thing elsewhere. (It internally uses `successResultOf` anyway.) [1]: https://github.com/twisted/twisted/pull/1736/commits/3f8c49816bc34f74167ea3e0579f0d5dde25aeec --- tests/handlers/test_federation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/handlers/test_federation.py b/tests/handlers/test_federation.py index e0eda545b91f..9afba7b0e80b 100644 --- a/tests/handlers/test_federation.py +++ b/tests/handlers/test_federation.py @@ -119,7 +119,7 @@ def test_rejected_message_event_state(self) -> None: join_event = self._build_and_send_join_event(OTHER_SERVER, OTHER_USER, room_id) # check the state group - sg = self.successResultOf( + sg = self.get_success( self.store._get_state_group_for_event(join_event.event_id) ) @@ -149,7 +149,7 @@ def test_rejected_message_event_state(self) -> None: self.assertIsNotNone(e.rejected_reason) # ... and the state group should be the same as before - sg2 = self.successResultOf(self.store._get_state_group_for_event(ev.event_id)) + sg2 = self.get_success(self.store._get_state_group_for_event(ev.event_id)) self.assertEqual(sg, sg2) @@ -172,7 +172,7 @@ def test_rejected_state_event_state(self) -> None: join_event = self._build_and_send_join_event(OTHER_SERVER, OTHER_USER, room_id) # check the state group - sg = self.successResultOf( + sg = self.get_success( self.store._get_state_group_for_event(join_event.event_id) ) @@ -203,7 +203,7 @@ def test_rejected_state_event_state(self) -> None: self.assertIsNotNone(e.rejected_reason) # ... and the state group should be the same as before - sg2 = self.successResultOf(self.store._get_state_group_for_event(ev.event_id)) + sg2 = self.get_success(self.store._get_state_group_for_event(ev.event_id)) self.assertEqual(sg, sg2) From a8db8fcc2bde74fcc22cc590e2189d4a10b78bb3 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Wed, 15 Jun 2022 10:39:07 +0100 Subject: [PATCH 3/3] Changelog --- changelog.d/13061.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/13061.misc diff --git a/changelog.d/13061.misc b/changelog.d/13061.misc new file mode 100644 index 000000000000..4c55e2b4edaa --- /dev/null +++ b/changelog.d/13061.misc @@ -0,0 +1 @@ +Fix type checking errors against Twisted trunk.