This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Improve type hints for cached decorator #15658
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f73d84f
Improve type hints on cached descriptor
clokep ea3071c
Improve the mypy plugin to return deferreds for caches.
clokep 6310a36
Newsfragment
clokep 4b3308c
Lint
clokep e9d02f4
Handle Awaitable in addition to Coroutine.
clokep 38ce596
Expand comments.
clokep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve type hints. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import re | ||
from typing import Generator | ||
from typing import Any, Generator | ||
from unittest.mock import Mock | ||
|
||
from twisted.internet import defer | ||
|
@@ -49,93 +49,81 @@ def setUp(self) -> None: | |
@defer.inlineCallbacks | ||
def test_regex_user_id_prefix_match( | ||
self, | ||
) -> Generator["defer.Deferred[object]", object, None]: | ||
) -> Generator["defer.Deferred[Any]", object, None]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.service.namespaces[ApplicationService.NS_USERS].append(_regex("@irc_.*")) | ||
self.event.sender = "@irc_foobar:matrix.org" | ||
self.assertTrue( | ||
( | ||
yield defer.ensureDeferred( | ||
self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
yield self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is already a |
||
) | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def test_regex_user_id_prefix_no_match( | ||
self, | ||
) -> Generator["defer.Deferred[object]", object, None]: | ||
) -> Generator["defer.Deferred[Any]", object, None]: | ||
self.service.namespaces[ApplicationService.NS_USERS].append(_regex("@irc_.*")) | ||
self.event.sender = "@someone_else:matrix.org" | ||
self.assertFalse( | ||
( | ||
yield defer.ensureDeferred( | ||
self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
yield self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
) | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def test_regex_room_member_is_checked( | ||
self, | ||
) -> Generator["defer.Deferred[object]", object, None]: | ||
) -> Generator["defer.Deferred[Any]", object, None]: | ||
self.service.namespaces[ApplicationService.NS_USERS].append(_regex("@irc_.*")) | ||
self.event.sender = "@someone_else:matrix.org" | ||
self.event.type = "m.room.member" | ||
self.event.state_key = "@irc_foobar:matrix.org" | ||
self.assertTrue( | ||
( | ||
yield defer.ensureDeferred( | ||
self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
yield self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
) | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def test_regex_room_id_match( | ||
self, | ||
) -> Generator["defer.Deferred[object]", object, None]: | ||
) -> Generator["defer.Deferred[Any]", object, None]: | ||
self.service.namespaces[ApplicationService.NS_ROOMS].append( | ||
_regex("!some_prefix.*some_suffix:matrix.org") | ||
) | ||
self.event.room_id = "!some_prefixs0m3th1nGsome_suffix:matrix.org" | ||
self.assertTrue( | ||
( | ||
yield defer.ensureDeferred( | ||
self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
yield self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
) | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def test_regex_room_id_no_match( | ||
self, | ||
) -> Generator["defer.Deferred[object]", object, None]: | ||
) -> Generator["defer.Deferred[Any]", object, None]: | ||
self.service.namespaces[ApplicationService.NS_ROOMS].append( | ||
_regex("!some_prefix.*some_suffix:matrix.org") | ||
) | ||
self.event.room_id = "!XqBunHwQIXUiqCaoxq:matrix.org" | ||
self.assertFalse( | ||
( | ||
yield defer.ensureDeferred( | ||
self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
yield self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
) | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def test_regex_alias_match( | ||
self, | ||
) -> Generator["defer.Deferred[object]", object, None]: | ||
def test_regex_alias_match(self) -> Generator["defer.Deferred[Any]", object, None]: | ||
self.service.namespaces[ApplicationService.NS_ALIASES].append( | ||
_regex("#irc_.*:matrix.org") | ||
) | ||
|
@@ -145,10 +133,8 @@ def test_regex_alias_match( | |
self.store.get_local_users_in_room = simple_async_mock([]) | ||
self.assertTrue( | ||
( | ||
yield defer.ensureDeferred( | ||
self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
yield self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
) | ||
) | ||
|
@@ -192,7 +178,7 @@ def test_exclusive_room(self) -> None: | |
@defer.inlineCallbacks | ||
def test_regex_alias_no_match( | ||
self, | ||
) -> Generator["defer.Deferred[object]", object, None]: | ||
) -> Generator["defer.Deferred[Any]", object, None]: | ||
self.service.namespaces[ApplicationService.NS_ALIASES].append( | ||
_regex("#irc_.*:matrix.org") | ||
) | ||
|
@@ -213,7 +199,7 @@ def test_regex_alias_no_match( | |
@defer.inlineCallbacks | ||
def test_regex_multiple_matches( | ||
self, | ||
) -> Generator["defer.Deferred[object]", object, None]: | ||
) -> Generator["defer.Deferred[Any]", object, None]: | ||
self.service.namespaces[ApplicationService.NS_ALIASES].append( | ||
_regex("#irc_.*:matrix.org") | ||
) | ||
|
@@ -223,18 +209,14 @@ def test_regex_multiple_matches( | |
self.store.get_local_users_in_room = simple_async_mock([]) | ||
self.assertTrue( | ||
( | ||
yield defer.ensureDeferred( | ||
self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
yield self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
) | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def test_interested_in_self( | ||
self, | ||
) -> Generator["defer.Deferred[object]", object, None]: | ||
def test_interested_in_self(self) -> Generator["defer.Deferred[Any]", object, None]: | ||
# make sure invites get through | ||
self.service.sender = "@appservice:name" | ||
self.service.namespaces[ApplicationService.NS_USERS].append(_regex("@irc_.*")) | ||
|
@@ -243,18 +225,14 @@ def test_interested_in_self( | |
self.event.state_key = self.service.sender | ||
self.assertTrue( | ||
( | ||
yield defer.ensureDeferred( | ||
self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
yield self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
) | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def test_member_list_match( | ||
self, | ||
) -> Generator["defer.Deferred[object]", object, None]: | ||
def test_member_list_match(self) -> Generator["defer.Deferred[Any]", object, None]: | ||
self.service.namespaces[ApplicationService.NS_USERS].append(_regex("@irc_.*")) | ||
# Note that @irc_fo:here is the AS user. | ||
self.store.get_local_users_in_room = simple_async_mock( | ||
|
@@ -265,10 +243,8 @@ def test_member_list_match( | |
self.event.sender = "@xmpp_foobar:matrix.org" | ||
self.assertTrue( | ||
( | ||
yield defer.ensureDeferred( | ||
self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
yield self.service.is_interested_in_event( | ||
self.event.event_id, self.event, self.store | ||
) | ||
) | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,15 +33,14 @@ def test_get_set_transactions(self) -> None: | |
destination retries, as well as testing tht we can set and get | ||
correctly. | ||
""" | ||
d = self.store.get_destination_retry_timings("example.com") | ||
r = self.get_success(d) | ||
r = self.get_success(self.store.get_destination_retry_timings("example.com")) | ||
self.assertIsNone(r) | ||
|
||
d = self.store.set_destination_retry_timings("example.com", 1000, 50, 100) | ||
self.get_success(d) | ||
self.get_success( | ||
self.store.set_destination_retry_timings("example.com", 1000, 50, 100) | ||
) | ||
|
||
d = self.store.get_destination_retry_timings("example.com") | ||
r = self.get_success(d) | ||
r = self.get_success(self.store.get_destination_retry_timings("example.com")) | ||
Comment on lines
-37
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
self.assertEqual( | ||
DestinationRetryTimings( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.