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

@ -10,7 +10,8 @@ import re
from typing import Dict, List, Iterator
from datetime import datetime
from .common import LazyLogger, get_files, group_by_key, cproperty, make_dict
from .core.common import LazyLogger, get_files, group_by_key, make_dict
from .core.compat import cached_property
from my.config import rtm as config
@ -28,14 +29,14 @@ class MyTodo:
self.todo = todo
self.revision = revision
@cproperty
@cached_property
def notes(self) -> List[str]:
# TODO can there be multiple??
desc = self.todo['DESCRIPTION']
notes = re.findall(r'---\n\n(.*?)\n\nUpdated:', desc, flags=re.DOTALL)
return notes
@cproperty
@cached_property
def tags(self) -> List[str]:
desc = self.todo['DESCRIPTION']
[tags_str] = re.findall(r'\nTags: (.*?)\n', desc, flags=re.DOTALL)
@ -44,11 +45,11 @@ class MyTodo:
tags = [t.strip() for t in tags_str.split(',')]
return tags
@cproperty
@cached_property
def uid(self) -> str:
return str(self.todo['UID'])
@cproperty
@cached_property
def title(self) -> str:
return str(self.todo['SUMMARY'])
@ -59,7 +60,7 @@ class MyTodo:
return str(self.todo['STATUS'])
# TODO tz?
@cproperty
@cached_property
def time(self) -> datetime:
t1 = self.todo['DTSTAMP'].dt
t2 = self.todo['LAST-MODIFIED'].dt