core: migrate code to benefit from 3.9 stuff (#401)
for now keeping ruff on 3.8 target version, need to sort out modules as well
This commit is contained in:
parent
bc7c3ac253
commit
d3f9a8e8b6
43 changed files with 515 additions and 404 deletions
|
@ -1,6 +1,7 @@
|
|||
"""
|
||||
Various helpers for reading org-mode data
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
@ -22,17 +23,20 @@ def parse_org_datetime(s: str) -> datetime:
|
|||
|
||||
# TODO I guess want to borrow inspiration from bs4? element type <-> tag; and similar logic for find_one, find_all
|
||||
|
||||
from typing import Callable, Iterable, TypeVar
|
||||
from collections.abc import Iterable
|
||||
from typing import Callable, TypeVar
|
||||
|
||||
from orgparse import OrgNode
|
||||
|
||||
V = TypeVar('V')
|
||||
|
||||
|
||||
def collect(n: OrgNode, cfun: Callable[[OrgNode], Iterable[V]]) -> Iterable[V]:
|
||||
yield from cfun(n)
|
||||
for c in n.children:
|
||||
yield from collect(c, cfun)
|
||||
|
||||
|
||||
from more_itertools import one
|
||||
from orgparse.extra import Table
|
||||
|
||||
|
@ -46,7 +50,7 @@ class TypedTable(Table):
|
|||
tt = super().__new__(TypedTable)
|
||||
tt.__dict__ = orig.__dict__
|
||||
blocks = list(orig.blocks)
|
||||
header = blocks[0] # fist block is schema
|
||||
header = blocks[0] # fist block is schema
|
||||
if len(header) == 2:
|
||||
# TODO later interpret first line as types
|
||||
header = header[1:]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue