Changeset - 43a2e1bec828
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-04-21 15:57:54
brettcsmith@brettcsmith.org
beancount_types: Add types related to loading the books.

These will help support loading methods in the books module.
2 files changed with 24 insertions and 4 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/beancount_types.py
Show inline comments
...
 
@@ -20,17 +20,23 @@ import datetime
 
import beancount.core.data as bc_data
 

	
 
from typing import (
 
    TYPE_CHECKING,
 
    Any,
 
    FrozenSet,
 
    Iterable,
 
    List,
 
    Mapping,
 
    NamedTuple,
 
    Optional,
 
    Set,
 
    Tuple,
 
    Type,
 
    Union,
 
)
 

	
 
if TYPE_CHECKING:
 
    from . import errors as errormod
 

	
 
Account = bc_data.Account
 
MetaKey = str
 
MetaValue = Any
...
 
@@ -42,6 +48,12 @@ class Directive(NamedTuple):
 
    date: datetime.date
 

	
 

	
 
class Error(NamedTuple):
 
    source: Optional[bc_data.Meta]
 
    message: str
 
    entry: Optional[Directive]
 

	
 

	
 
class Transaction(Directive):
 
    flag: bc_data.Flag
 
    payee: Optional[str]
...
 
@@ -54,3 +66,8 @@ class Transaction(Directive):
 
ALL_DIRECTIVES: FrozenSet[Type[Directive]] = frozenset([
 
    Transaction,
 
])
 

	
 
Entries = List[Directive]
 
Errors = List[Union[Error, 'errormod.Error']]
 
OptionsMap = Mapping[str, Any]
 
LoadResult = Tuple[Entries, Errors, OptionsMap]
conservancy_beancount/plugin/__init__.py
Show inline comments
...
 
@@ -32,6 +32,9 @@ from typing import (
 
from ..beancount_types import (
 
    ALL_DIRECTIVES,
 
    Directive,
 
    Entries,
 
    Errors,
 
    OptionsMap,
 
)
 
from .. import config as configmod
 
from .core import (
...
 
@@ -117,15 +120,15 @@ class HookRegistry:
 

	
 

	
 
def run(
 
        entries: List[Directive],
 
        options_map: Dict[str, Any],
 
        entries: Entries,
 
        options_map: OptionsMap,
 
        config: str='',
 
        hook_registry: Optional[HookRegistry]=None,
 
) -> Tuple[List[Directive], List[Error]]:
 
) -> Tuple[Entries, Errors]:
 
    if hook_registry is None:
 
        hook_registry = HookRegistry()
 
        hook_registry.load_included_hooks()
 
    errors: List[Error] = []
 
    errors: Errors = []
 
    hooks: Dict[HookName, List[Hook]] = {
 
        # 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]
0 comments (0 inline, 0 general)