From ac7238ecf47ed1255c4210dbf66234024ea0df8c Mon Sep 17 00:00:00 2001 From: Sean Quah Date: Thu, 30 Sep 2021 12:28:01 +0100 Subject: [PATCH 1/2] Update `_wrap_in_base_path` type hints to preserve function arguments --- synapse/rest/media/v1/filepath.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/synapse/rest/media/v1/filepath.py b/synapse/rest/media/v1/filepath.py index 08bd85f66445..eb66b749a21b 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 _wrapped(self: "MediaFilePaths", *args: Any, **kwargs: Any) -> str: path = func(self, *args, **kwargs) return os.path.join(self.base_path, path) - return _wrapped + return cast(F, _wrapped) class MediaFilePaths: From b2e5c998c1c9f5229e2317e043a641208615310c Mon Sep 17 00:00:00 2001 From: Sean Quah Date: Tue, 12 Oct 2021 16:15:29 +0100 Subject: [PATCH 2/2] Add newsfile --- changelog.d/11055.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/11055.misc diff --git a/changelog.d/11055.misc b/changelog.d/11055.misc new file mode 100644 index 000000000000..27688c321436 --- /dev/null +++ b/changelog.d/11055.misc @@ -0,0 +1 @@ +Improve type hints for `_wrap_in_base_path` decorator used by `MediaFilePaths`.