Changeset - ca12496880d6
[Not reviewed]
0 10 0
Brett Smith - 3 years ago 2021-02-26 21:13:02
brettcsmith@brettcsmith.org
typing: Updates to pass type checking under mypy>=0.800.

Most of these account for the fact that mypy now reports that Hashable is
not an allowed return type for sort key functions.

That, plus the new ignore for the regression in config.py.
10 files changed with 22 insertions and 18 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/beancount_types.py
Show inline comments
...
 
@@ -30,2 +30,5 @@ if TYPE_CHECKING:
 
    from . import errors as errormod
 
    from _typeshed import SupportsLessThan as Sortable
 
else:
 
    from typing import Hashable as Sortable
 

	
conservancy_beancount/cliutil.py
Show inline comments
...
 
@@ -44,3 +44,2 @@ from typing import (
 
    Generic,
 
    Hashable,
 
    IO,
...
 
@@ -60,2 +59,3 @@ from .beancount_types import (
 
    MetaKey,
 
    Sortable,
 
)
...
 
@@ -116,3 +116,3 @@ class EnumArgument(Generic[ET]):
 
        """Return a user-formatted string of enum names"""
 
        sortkey: Callable[[ET], Hashable] = getattr(
 
        sortkey: Callable[[ET], Sortable] = getattr(
 
            self.base, '_choices_sortkey', self._choices_sortkey,
...
 
@@ -124,3 +124,3 @@ class EnumArgument(Generic[ET]):
 

	
 
    def _choices_sortkey(self, choice: ET) -> Hashable:
 
    def _choices_sortkey(self, choice: ET) -> Sortable:
 
        return choice.name
...
 
@@ -209,3 +209,3 @@ class ExtendAction(argparse.Action):
 
          action=ExtendAction,
 
          const=regexp_pattern,  # default is r'\s*,\s*'
 
          const=regexp_pattern,  # default is '\\s*,\\s*'
 
          ...,
...
 
@@ -260,3 +260,3 @@ class LogLevel(enum.IntEnum):
 

	
 
    def _choices_sortkey(self) -> Hashable:
 
    def _choices_sortkey(self) -> Sortable:
 
        return self.value
conservancy_beancount/config.py
Show inline comments
...
 
@@ -230,2 +230,3 @@ class Config:
 
            credentials = self.rt_credentials()
 
        return self._rt_wrapper(credentials, client)
 
        # type ignore for <https://github.com/python/typeshed/issues/4638>
 
        return self._rt_wrapper(credentials, client)  # type:ignore[arg-type]
conservancy_beancount/reconcile/paypal.py
Show inline comments
...
 
@@ -36,3 +36,2 @@ from typing import (
 
    Any,
 
    Hashable,
 
    Iterable,
...
 
@@ -48,2 +47,5 @@ from typing import (
 
)
 
from ..beancount_types import (
 
    Sortable,
 
)
 

	
...
 
@@ -166,3 +168,3 @@ class PayPalReconciler:
 

	
 
    def sort_key(self) -> Hashable:
 
    def sort_key(self) -> Sortable:
 
        try:
conservancy_beancount/reports/balance_sheet.py
Show inline comments
...
 
@@ -23,3 +23,2 @@ from typing import (
 
    Dict,
 
    Hashable,
 
    Iterable,
conservancy_beancount/reports/budget.py
Show inline comments
...
 
@@ -29,3 +29,2 @@ from typing import (
 
    Dict,
 
    Hashable,
 
    Iterable,
conservancy_beancount/reports/core.py
Show inline comments
...
 
@@ -54,3 +54,2 @@ from typing import (
 
    Generic,
 
    Hashable,
 
    Iterable,
...
 
@@ -72,2 +71,3 @@ from ..beancount_types import (
 
    MetaValue,
 
    Sortable,
 
)
...
 
@@ -441,3 +441,3 @@ class Balances:
 
        norm_func = normalize_amount_func(f'{account}:RootsOK')
 
        def sortkey(acct: data.Account) -> Hashable:
 
        def sortkey(acct: data.Account) -> Sortable:
 
            prefix, _, _ = acct.rpartition(':')
conservancy_beancount/reports/ledger.py
Show inline comments
...
 
@@ -48,3 +48,2 @@ from typing import (
 
    Dict,
 
    Hashable,
 
    Iterable,
...
 
@@ -63,2 +62,3 @@ from typing import (
 
from ..beancount_types import (
 
    Sortable,
 
    Transaction,
...
 
@@ -532,3 +532,3 @@ class ReportType(enum.IntFlag):
 

	
 
    def _choices_sortkey(self) -> Hashable:
 
    def _choices_sortkey(self) -> Sortable:
 
        subtype, _, maintype = self.name.partition('_')
conservancy_beancount/tools/opening_balances.py
Show inline comments
...
 
@@ -29,3 +29,2 @@ from typing import (
 
    Dict,
 
    Hashable,
 
    Iterable,
...
 
@@ -43,2 +42,3 @@ from ..beancount_types import (
 
    MetaValue,
 
    Sortable,
 
    Transaction,
...
 
@@ -78,3 +78,3 @@ class AccountWithFund(NamedTuple):
 

	
 
    def sortkey(self) -> Hashable:
 
    def sortkey(self) -> Sortable:
 
        account, fund = self
conservancy_beancount/tools/sort_entries.py
Show inline comments
...
 
@@ -24,3 +24,2 @@ from beancount.parser import printer as bc_printer
 
from typing import (
 
    Hashable,
 
    Optional,
...
 
@@ -33,2 +32,3 @@ from ..beancount_types import (
 
    Errors,
 
    Sortable,
 
)
...
 
@@ -58,3 +58,3 @@ def parse_arguments(arglist: Optional[Sequence[str]]=None) -> argparse.Namespace
 

	
 
def entry_sorter(entry: Directive) -> Hashable:
 
def entry_sorter(entry: Directive) -> Sortable:
 
    type_name = type(entry).__name__
0 comments (0 inline, 0 general)