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

Improve type annotations for the helper methods on a CachedFunction. #14685

Merged
merged 2 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/14685.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve type annotations for the helper methods on a `CachedFunction`.
6 changes: 3 additions & 3 deletions synapse/util/caches/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@


class CachedFunction(Generic[F]):
invalidate: Any = None
invalidate_all: Any = None
prefill: Any = None
invalidate: Callable[[Tuple[Any, ...]], None]
Copy link
Contributor

@MadLittleMods MadLittleMods Dec 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing/improving this!

For my own reference, related to #13863 where we weren't invalidating the have_seen_event cache as expected but that was because we weren't putting keys in the cache the right way.

The first pass there adjusted the invalidate usage but that was just masking the underlying problem and this typing would have caught that.

And just generally helps confidence that we're calling this correctly all over the place!!

invalidate_all: Callable[[], None]
prefill: Callable[[Tuple[Any, ...], Any], None]
Comment on lines +56 to +58
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously these were Optional and defaulted to None, was that incorrect?

Looks like these are always available and never None.

cache: Any = None
num_args: Any = None

Expand Down