core: Make MetadataEnum aliases optional.
This commit is contained in:
parent
7bc0ded9c6
commit
cbd94d9b75
2 changed files with 5 additions and 4 deletions
|
@ -23,6 +23,7 @@ from .. import errors as errormod
|
||||||
|
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
|
Dict,
|
||||||
FrozenSet,
|
FrozenSet,
|
||||||
Generic,
|
Generic,
|
||||||
Iterable,
|
Iterable,
|
||||||
|
@ -113,7 +114,7 @@ class MetadataEnum:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
key: MetaKey,
|
key: MetaKey,
|
||||||
standard_values: Iterable[MetaValueEnum],
|
standard_values: Iterable[MetaValueEnum],
|
||||||
aliases_map: Mapping[MetaValueEnum, MetaValueEnum],
|
aliases_map: Optional[Mapping[MetaValueEnum, MetaValueEnum]]=None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Specify allowed values and aliases for this metadata.
|
"""Specify allowed values and aliases for this metadata.
|
||||||
|
|
||||||
|
@ -129,9 +130,9 @@ class MetadataEnum:
|
||||||
"""
|
"""
|
||||||
self.key = key
|
self.key = key
|
||||||
self._stdvalues = frozenset(standard_values)
|
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)
|
self._aliases.update((v, v) for v in standard_values)
|
||||||
assert self._stdvalues == set(self._aliases.values())
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return "{}<{}>".format(type(self).__name__, self.key)
|
return "{}<{}>".format(type(self).__name__, self.key)
|
||||||
|
|
|
@ -43,7 +43,7 @@ class MetaTaxImplication(core._NormalizePostingMetadataHook):
|
||||||
'USA-Corporation',
|
'USA-Corporation',
|
||||||
'USA-LLC-No-1099',
|
'USA-LLC-No-1099',
|
||||||
'W2',
|
'W2',
|
||||||
], {})
|
])
|
||||||
|
|
||||||
def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
|
def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
|
||||||
return bool(
|
return bool(
|
||||||
|
|
Loading…
Reference in a new issue