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

Commit 8eaffe0

Browse files
authored
Update _wrap_in_base_path type hints to preserve function arguments (#11055)
1 parent 77ea030 commit 8eaffe0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

changelog.d/11055.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve type hints for `_wrap_in_base_path` decorator used by `MediaFilePaths`.

synapse/rest/media/v1/filepath.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
import functools
1717
import os
1818
import re
19-
from typing import Any, Callable, List
19+
from typing import Any, Callable, List, TypeVar, cast
2020

2121
NEW_FORMAT_ID_RE = re.compile(r"^\d\d\d\d-\d\d-\d\d")
2222

2323

24-
def _wrap_in_base_path(func: Callable[..., str]) -> Callable[..., str]:
24+
F = TypeVar("F", bound=Callable[..., str])
25+
26+
27+
def _wrap_in_base_path(func: F) -> F:
2528
"""Takes a function that returns a relative path and turns it into an
2629
absolute path based on the location of the primary media store
2730
"""
@@ -31,7 +34,7 @@ def _wrapped(self: "MediaFilePaths", *args: Any, **kwargs: Any) -> str:
3134
path = func(self, *args, **kwargs)
3235
return os.path.join(self.base_path, path)
3336

34-
return _wrapped
37+
return cast(F, _wrapped)
3538

3639

3740
class MediaFilePaths:

0 commit comments

Comments
 (0)