core: Make MetadataEnum aliases optional.

This commit is contained in:
Brett Smith 2020-03-18 18:23:42 -04:00
parent 7bc0ded9c6
commit cbd94d9b75
2 changed files with 5 additions and 4 deletions

View file

@ -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)

View file

@ -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(