core/general: move cached_property into compat, use standard implementation from python3.8

This commit is contained in:
Dima Gerasimov 2022-05-31 13:06:29 +01:00 committed by karlicoss
parent 711157e0f5
commit 4e59a65f9a
6 changed files with 38 additions and 27 deletions

View file

@ -6,8 +6,8 @@ from typing import NamedTuple
import json
from typing import Dict, Iterator
from ..common import cproperty, get_files
from ..error import Res, unwrap
from ..core import get_files, Res, unwrap
from ..core.compat import cached_property
from ..core.konsume import ignore, wrap
from kython import fget
@ -46,18 +46,18 @@ class Competition(NamedTuple):
contest: str
cmap: Cmap
@cproperty
@cached_property
def uid(self) -> Cid:
return self.contest_id
def __hash__(self):
return hash(self.contest_id)
@cproperty
@cached_property
def when(self) -> datetime:
return self.cmap[self.uid].when
@cproperty
@cached_property
def summary(self) -> str:
return f'participated in {self.contest}' # TODO

View file

@ -6,8 +6,9 @@ from typing import NamedTuple
import json
from typing import Dict, Iterator
from ..common import cproperty, get_files
from ..error import Res, unwrap
from ..core import get_files, Res, unwrap
from ..core.compat import cached_property
from ..core.error import Res, unwrap
# TODO get rid of fget?
from kython import fget
@ -26,18 +27,18 @@ class Competition(NamedTuple):
percentile: float
dates: str
@cproperty
@cached_property
def uid(self) -> str:
return self.contest_id
def __hash__(self):
return hash(self.contest_id)
@cproperty
@cached_property
def when(self) -> datetime:
return datetime.strptime(self.dates, '%Y-%m-%dT%H:%M:%S.%fZ')
@cproperty
@cached_property
def summary(self) -> str:
return f'participated in {self.contest}: {self.percentile:.0f}'