add @classproperty, change set_repo to not require the parent

This commit is contained in:
Dima Gerasimov 2020-05-09 20:03:35 +01:00
parent 5f4acfddee
commit 66453cb29b
3 changed files with 30 additions and 4 deletions

View file

@ -195,3 +195,27 @@ def fastermime(path: PathIsh) -> str:
Json = Dict[str, Any]
from typing import TypeVar, Callable, Generic
_C = TypeVar('_C')
_R = TypeVar('_R')
# https://stackoverflow.com/a/5192374/706389
class classproperty(Generic[_R]):
def __init__(self, f: Callable[[_C], _R]) -> None:
self.f = f
def __get__(self, obj: None, cls: _C) -> _R:
return self.f(cls)
# hmm, this doesn't really work with mypy well..
# https://github.com/python/mypy/issues/6244
# class staticproperty(Generic[_R]):
# def __init__(self, f: Callable[[], _R]) -> None:
# self.f = f
#
# def __get__(self) -> _R:
# return self.f()