beancount_types: Add types related to loading the books.
These will help support loading methods in the books module.
This commit is contained in:
parent
855c1c2bf0
commit
43a2e1bec8
2 changed files with 24 additions and 4 deletions
|
@ -20,17 +20,23 @@ import datetime
|
||||||
import beancount.core.data as bc_data
|
import beancount.core.data as bc_data
|
||||||
|
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
FrozenSet,
|
FrozenSet,
|
||||||
Iterable,
|
Iterable,
|
||||||
List,
|
List,
|
||||||
|
Mapping,
|
||||||
NamedTuple,
|
NamedTuple,
|
||||||
Optional,
|
Optional,
|
||||||
Set,
|
Set,
|
||||||
Tuple,
|
Tuple,
|
||||||
Type,
|
Type,
|
||||||
|
Union,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from . import errors as errormod
|
||||||
|
|
||||||
Account = bc_data.Account
|
Account = bc_data.Account
|
||||||
MetaKey = str
|
MetaKey = str
|
||||||
MetaValue = Any
|
MetaValue = Any
|
||||||
|
@ -42,6 +48,12 @@ class Directive(NamedTuple):
|
||||||
date: datetime.date
|
date: datetime.date
|
||||||
|
|
||||||
|
|
||||||
|
class Error(NamedTuple):
|
||||||
|
source: Optional[bc_data.Meta]
|
||||||
|
message: str
|
||||||
|
entry: Optional[Directive]
|
||||||
|
|
||||||
|
|
||||||
class Transaction(Directive):
|
class Transaction(Directive):
|
||||||
flag: bc_data.Flag
|
flag: bc_data.Flag
|
||||||
payee: Optional[str]
|
payee: Optional[str]
|
||||||
|
@ -54,3 +66,8 @@ class Transaction(Directive):
|
||||||
ALL_DIRECTIVES: FrozenSet[Type[Directive]] = frozenset([
|
ALL_DIRECTIVES: FrozenSet[Type[Directive]] = frozenset([
|
||||||
Transaction,
|
Transaction,
|
||||||
])
|
])
|
||||||
|
|
||||||
|
Entries = List[Directive]
|
||||||
|
Errors = List[Union[Error, 'errormod.Error']]
|
||||||
|
OptionsMap = Mapping[str, Any]
|
||||||
|
LoadResult = Tuple[Entries, Errors, OptionsMap]
|
||||||
|
|
|
@ -32,6 +32,9 @@ from typing import (
|
||||||
from ..beancount_types import (
|
from ..beancount_types import (
|
||||||
ALL_DIRECTIVES,
|
ALL_DIRECTIVES,
|
||||||
Directive,
|
Directive,
|
||||||
|
Entries,
|
||||||
|
Errors,
|
||||||
|
OptionsMap,
|
||||||
)
|
)
|
||||||
from .. import config as configmod
|
from .. import config as configmod
|
||||||
from .core import (
|
from .core import (
|
||||||
|
@ -117,15 +120,15 @@ class HookRegistry:
|
||||||
|
|
||||||
|
|
||||||
def run(
|
def run(
|
||||||
entries: List[Directive],
|
entries: Entries,
|
||||||
options_map: Dict[str, Any],
|
options_map: OptionsMap,
|
||||||
config: str='',
|
config: str='',
|
||||||
hook_registry: Optional[HookRegistry]=None,
|
hook_registry: Optional[HookRegistry]=None,
|
||||||
) -> Tuple[List[Directive], List[Error]]:
|
) -> Tuple[Entries, Errors]:
|
||||||
if hook_registry is None:
|
if hook_registry is None:
|
||||||
hook_registry = HookRegistry()
|
hook_registry = HookRegistry()
|
||||||
hook_registry.load_included_hooks()
|
hook_registry.load_included_hooks()
|
||||||
errors: List[Error] = []
|
errors: Errors = []
|
||||||
hooks: Dict[HookName, List[Hook]] = {
|
hooks: Dict[HookName, List[Hook]] = {
|
||||||
# mypy thinks NamedTuples don't have __name__ but they do at runtime.
|
# mypy thinks NamedTuples don't have __name__ but they do at runtime.
|
||||||
t.__name__: [] for t in bc_data.ALL_DIRECTIVES # type:ignore[attr-defined]
|
t.__name__: [] for t in bc_data.ALL_DIRECTIVES # type:ignore[attr-defined]
|
||||||
|
|
Loading…
Reference in a new issue