From cbd94d9b75e3f62e438fa978403e757ef124973e Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Wed, 18 Mar 2020 18:23:42 -0400 Subject: [PATCH] core: Make MetadataEnum aliases optional. --- conservancy_beancount/plugin/core.py | 7 ++++--- conservancy_beancount/plugin/meta_tax_implication.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/conservancy_beancount/plugin/core.py b/conservancy_beancount/plugin/core.py index 39dc7e2..f2fb69b 100644 --- a/conservancy_beancount/plugin/core.py +++ b/conservancy_beancount/plugin/core.py @@ -23,6 +23,7 @@ from .. import errors as errormod from typing import ( Any, + Dict, FrozenSet, Generic, Iterable, @@ -113,7 +114,7 @@ class MetadataEnum: def __init__(self, key: MetaKey, standard_values: Iterable[MetaValueEnum], - aliases_map: Mapping[MetaValueEnum, MetaValueEnum], + aliases_map: Optional[Mapping[MetaValueEnum, MetaValueEnum]]=None, ) -> None: """Specify allowed values and aliases for this metadata. @@ -129,9 +130,9 @@ class MetadataEnum: """ self.key = key self._stdvalues = frozenset(standard_values) - self._aliases = dict(aliases_map) + self._aliases: Dict[MetaValueEnum, MetaValueEnum] = dict(aliases_map or ()) + assert self._stdvalues.issuperset(self._aliases.values()) self._aliases.update((v, v) for v in standard_values) - assert self._stdvalues == set(self._aliases.values()) def __repr__(self) -> str: return "{}<{}>".format(type(self).__name__, self.key) diff --git a/conservancy_beancount/plugin/meta_tax_implication.py b/conservancy_beancount/plugin/meta_tax_implication.py index 3f0a61a..2716dd1 100644 --- a/conservancy_beancount/plugin/meta_tax_implication.py +++ b/conservancy_beancount/plugin/meta_tax_implication.py @@ -43,7 +43,7 @@ class MetaTaxImplication(core._NormalizePostingMetadataHook): 'USA-Corporation', 'USA-LLC-No-1099', 'W2', - ], {}) + ]) def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool: return bool(