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

Commit

Permalink
Update _wrap_in_base_path type hints to preserve function arguments (
Browse files Browse the repository at this point in the history
  • Loading branch information
squahtx authored Oct 12, 2021
1 parent 77ea030 commit 8eaffe0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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

0 comments on commit 8eaffe0

Please sign in to comment.