Changeset View
Changeset View
Standalone View
Standalone View
looper/decorators.py
| from typing import Any, Callable, TypeVar, cast | from typing import Any, Callable, TypeVar, cast | ||||
| import functools | import functools | ||||
| import looper.exceptions | import looper.exceptions | ||||
| F = TypeVar('F', bound=Callable[..., Any]) | F = TypeVar('F', bound=Callable[..., Any]) | ||||
| def short_description(description): | def short_description(description: str) -> Callable[[F], F]: | ||||
| """Set wrapped.short_description to 'description'. | """Set wrapped.short_description to 'description'. | ||||
| This makes it possible to stick to PEP8 (two newlines before/after | This makes it possible to stick to PEP8 (two newlines before/after | ||||
| function) and still keep the short description next to the function | function) and still keep the short description next to the function | ||||
| itself. | itself. | ||||
| """ | """ | ||||
| def decorator(wrapped): | def decorator(wrapped: F) -> F: | ||||
| wrapped.short_description = description | setattr(wrapped, 'short_description', description) | ||||
| return wrapped | return wrapped | ||||
| return decorator | return decorator | ||||
| def requires_status(*required_statuses: str) -> Callable[[F], F]: | def requires_status(*required_statuses: str) -> Callable[[F], F]: | ||||
| """Function decorator to assert a model has a certain status. | """Function decorator to assert a model has a certain status. | ||||
| Show All 19 Lines | |||||