From 959bda307b31036bc9c4eb207184b0331e89682c Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Sun, 29 Mar 2020 23:28:03 -0400 Subject: [PATCH] typing: Refine any generics when possible. These were tightened up by running mypy with --disallow-any-generics and cleaning up reported errors. There are still a couple of cases I don't know how to deal with right now that prevent me from setting that option permanently: * plugin/__init__.py sets up a dict where the key is a Directive and its value is a set of hooks that correspond to that type of directive. The relationship between key and value is not expressable through the type system, and any other solution would make the code way more involved and less dynamic. * The type variable used in _GenericRange still isn't quite right, in the sense that specifying a value for CT creates more errors I don't know how to deal with. Protocols seem like the right solution for that but they apparently didn't land for Python 3.7 that I can see. --- conservancy_beancount/beancount_types.py | 4 ++-- conservancy_beancount/errors.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conservancy_beancount/beancount_types.py b/conservancy_beancount/beancount_types.py index e89197b..56956ec 100644 --- a/conservancy_beancount/beancount_types.py +++ b/conservancy_beancount/beancount_types.py @@ -46,8 +46,8 @@ class Transaction(Directive): flag: bc_data.Flag payee: Optional[str] narration: str - tags: Set - links: Set + tags: Set[str] + links: Set[str] postings: List[Posting] diff --git a/conservancy_beancount/errors.py b/conservancy_beancount/errors.py index 486676a..62891c5 100644 --- a/conservancy_beancount/errors.py +++ b/conservancy_beancount/errors.py @@ -118,7 +118,7 @@ class InvalidMetadataError(Error): key: MetaKey, value: Optional[MetaValue]=None, post: Optional[bc_data.Posting]=None, - need_type: Type=str, + need_type: Type[object]=str, source: Meta=None, ) -> None: if post is None: