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

Update _wrap_in_base_path type hints to preserve function arguments #11055

Merged
merged 2 commits into from
Oct 12, 2021
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/11055.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve type hints for `_wrap_in_base_path` decorator used by `MediaFilePaths`.
9 changes: 6 additions & 3 deletions synapse/rest/media/v1/filepath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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:
Expand Down