Skip to content

Commit

Permalink
Improve typing on utils.transactional.
Browse files Browse the repository at this point in the history
This actually propagates the signature of the callable being wrapped,
though it requires silencing mypy about the implementation.
  • Loading branch information
TallJimbo committed Aug 18, 2020
1 parent 42d7d4b commit b384cc8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions python/lsst/daf/butler/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
Mapping,
Optional,
Type,
TypeVar,
Union,
)

Expand Down Expand Up @@ -237,7 +238,10 @@ def __call__(cls) -> Any: # type: ignore
return cls._instances[cls]


def transactional(func: Callable) -> Callable:
F = TypeVar("F", bound=Callable)


def transactional(func: F) -> F:
"""Decorator that wraps a method and makes it transactional.
This depends on the class also defining a `transaction` method
Expand All @@ -247,7 +251,7 @@ def transactional(func: Callable) -> Callable:
def inner(self: Any, *args: Any, **kwargs: Any) -> Any:
with self.transaction():
return func(self, *args, **kwargs)
return inner
return inner # type: ignore


def stripIfNotNone(s: Optional[str]) -> Optional[str]:
Expand Down

0 comments on commit b384cc8

Please sign in to comment.