Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
5331fb5b
Unverified
Commit
5331fb5b
authored
2 years ago
by
David Robertson
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
allow `on_invalidate=None` in `@cached` methods (#12769)
parent
6edefef6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/12769.misc
+1
-0
1 addition, 0 deletions
changelog.d/12769.misc
scripts-dev/mypy_synapse_plugin.py
+16
-9
16 additions, 9 deletions
scripts-dev/mypy_synapse_plugin.py
synapse/storage/databases/main/roommember.py
+2
-1
2 additions, 1 deletion
synapse/storage/databases/main/roommember.py
with
19 additions
and
10 deletions
changelog.d/12769.misc
0 → 100644
+
1
−
0
View file @
5331fb5b
Tweak the mypy plugin so that `@cached` can accept `on_invalidate=None`.
This diff is collapsed.
Click to expand it.
scripts-dev/mypy_synapse_plugin.py
+
16
−
9
View file @
5331fb5b
...
...
@@ -21,7 +21,7 @@ from typing import Callable, Optional, Type
from
mypy.nodes
import
ARG_NAMED_OPT
from
mypy.plugin
import
MethodSigContext
,
Plugin
from
mypy.typeops
import
bind_self
from
mypy.types
import
CallableType
,
NoneType
from
mypy.types
import
CallableType
,
NoneType
,
UnionType
class
SynapsePlugin
(
Plugin
):
...
...
@@ -72,13 +72,20 @@ def cached_function_method_signature(ctx: MethodSigContext) -> CallableType:
# Third, we add an optional "on_invalidate" argument.
#
# This is a callable which accepts no input and returns nothing.
calltyp
=
CallableType
(
arg_types
=
[],
arg_kinds
=
[],
arg_names
=
[],
ret_type
=
NoneType
(),
fallback
=
ctx
.
api
.
named_generic_type
(
"
builtins.function
"
,
[]),
# This is a either
# - a callable which accepts no input and returns nothing, or
# - None.
calltyp
=
UnionType
(
[
NoneType
(),
CallableType
(
arg_types
=
[],
arg_kinds
=
[],
arg_names
=
[],
ret_type
=
NoneType
(),
fallback
=
ctx
.
api
.
named_generic_type
(
"
builtins.function
"
,
[]),
),
]
)
arg_types
.
append
(
calltyp
)
...
...
@@ -95,7 +102,7 @@ def cached_function_method_signature(ctx: MethodSigContext) -> CallableType:
def
plugin
(
version
:
str
)
->
Type
[
SynapsePlugin
]:
# This is the entry point of the plugin, and let
'
s us deal with the fact
# This is the entry point of the plugin, and lets us deal with the fact
# that the mypy plugin interface is *not* stable by looking at the version
# string.
#
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/databases/main/roommember.py
+
2
−
1
View file @
5331fb5b
...
...
@@ -15,6 +15,7 @@
import
logging
from
typing
import
(
TYPE_CHECKING
,
Callable
,
Collection
,
Dict
,
FrozenSet
,
...
...
@@ -634,7 +635,7 @@ class RoomMemberWorkerStore(EventsWorkerStore):
)
async
def
get_rooms_for_user
(
self
,
user_id
:
str
,
on_invalidate
=
None
self
,
user_id
:
str
,
on_invalidate
:
Optional
[
Callable
[[],
None
]]
=
None
)
->
FrozenSet
[
str
]:
"""
Returns a set of room_ids the user is currently joined to.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment