summary refs log tree commit diff
diff options
context:
space:
mode:
authorSean Quah <8349537+squahtx@users.noreply.github.com>2021-10-12 18:19:21 +0100
committerGitHub <noreply@github.com>2021-10-12 18:19:21 +0100
commit8eaffe013cd37cdf9ec34875fc13d9b1249919e7 (patch)
treeb3b745fac7f9ac386241d84461899779ccb17d64
parentMerge remote-tracking branch 'origin/release-v1.45' into develop (diff)
downloadsynapse-8eaffe013cd37cdf9ec34875fc13d9b1249919e7.tar.xz
Update `_wrap_in_base_path` type hints to preserve function arguments (#11055)
-rw-r--r--changelog.d/11055.misc1
-rw-r--r--synapse/rest/media/v1/filepath.py9
2 files changed, 7 insertions, 3 deletions
diff --git a/changelog.d/11055.misc b/changelog.d/11055.misc
new file mode 100644

index 0000000000..27688c3214 --- /dev/null +++ b/changelog.d/11055.misc
@@ -0,0 +1 @@ +Improve type hints for `_wrap_in_base_path` decorator used by `MediaFilePaths`. diff --git a/synapse/rest/media/v1/filepath.py b/synapse/rest/media/v1/filepath.py
index 08bd85f664..eb66b749a2 100644 --- a/synapse/rest/media/v1/filepath.py +++ b/synapse/rest/media/v1/filepath.py
@@ -16,12 +16,15 @@ import functools import os import re -from typing import Any, Callable, List +from typing import Any, Callable, List, TypeVar, cast NEW_FORMAT_ID_RE = re.compile(r"^\d\d\d\d-\d\d-\d\d") -def _wrap_in_base_path(func: Callable[..., str]) -> Callable[..., str]: +F = TypeVar("F", bound=Callable[..., str]) + + +def _wrap_in_base_path(func: F) -> F: """Takes a function that returns a relative path and turns it into an absolute path based on the location of the primary media store """ @@ -31,7 +34,7 @@ def _wrap_in_base_path(func: Callable[..., str]) -> Callable[..., str]: path = func(self, *args, **kwargs) return os.path.join(self.base_path, path) - return _wrapped + return cast(F, _wrapped) class MediaFilePaths: