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.
This commit is contained in:
parent
6752a40206
commit
ca12496880
10 changed files with 22 additions and 18 deletions
|
@ -28,6 +28,9 @@ from typing import (
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from . import errors as errormod
|
from . import errors as errormod
|
||||||
|
from _typeshed import SupportsLessThan as Sortable
|
||||||
|
else:
|
||||||
|
from typing import Hashable as Sortable
|
||||||
|
|
||||||
Account = bc_data.Account
|
Account = bc_data.Account
|
||||||
Currency = bc_data.Currency
|
Currency = bc_data.Currency
|
||||||
|
|
|
@ -42,7 +42,6 @@ from typing import (
|
||||||
Callable,
|
Callable,
|
||||||
Container,
|
Container,
|
||||||
Generic,
|
Generic,
|
||||||
Hashable,
|
|
||||||
IO,
|
IO,
|
||||||
Iterable,
|
Iterable,
|
||||||
Iterator,
|
Iterator,
|
||||||
|
@ -58,6 +57,7 @@ from typing import (
|
||||||
)
|
)
|
||||||
from .beancount_types import (
|
from .beancount_types import (
|
||||||
MetaKey,
|
MetaKey,
|
||||||
|
Sortable,
|
||||||
)
|
)
|
||||||
|
|
||||||
ET = TypeVar('ET', bound=enum.Enum)
|
ET = TypeVar('ET', bound=enum.Enum)
|
||||||
|
@ -114,7 +114,7 @@ class EnumArgument(Generic[ET]):
|
||||||
|
|
||||||
def choices_str(self, sep: str=', ', fmt: str='{!r}') -> str:
|
def choices_str(self, sep: str=', ', fmt: str='{!r}') -> str:
|
||||||
"""Return a user-formatted string of enum names"""
|
"""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,
|
self.base, '_choices_sortkey', self._choices_sortkey,
|
||||||
)
|
)
|
||||||
return sep.join(
|
return sep.join(
|
||||||
|
@ -122,7 +122,7 @@ class EnumArgument(Generic[ET]):
|
||||||
for choice in sorted(self.base, key=sortkey)
|
for choice in sorted(self.base, key=sortkey)
|
||||||
)
|
)
|
||||||
|
|
||||||
def _choices_sortkey(self, choice: ET) -> Hashable:
|
def _choices_sortkey(self, choice: ET) -> Sortable:
|
||||||
return choice.name
|
return choice.name
|
||||||
|
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ class ExtendAction(argparse.Action):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--option', ...,
|
'--option', ...,
|
||||||
action=ExtendAction,
|
action=ExtendAction,
|
||||||
const=regexp_pattern, # default is r'\s*,\s*'
|
const=regexp_pattern, # default is '\\s*,\\s*'
|
||||||
...,
|
...,
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
@ -258,7 +258,7 @@ class LogLevel(enum.IntEnum):
|
||||||
ERR = ERROR
|
ERR = ERROR
|
||||||
CRIT = CRITICAL
|
CRIT = CRITICAL
|
||||||
|
|
||||||
def _choices_sortkey(self) -> Hashable:
|
def _choices_sortkey(self) -> Sortable:
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -228,4 +228,5 @@ class Config:
|
||||||
) -> Optional[rtutil.RT]:
|
) -> Optional[rtutil.RT]:
|
||||||
if credentials is None:
|
if credentials is None:
|
||||||
credentials = self.rt_credentials()
|
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]
|
||||||
|
|
|
@ -34,7 +34,6 @@ from ..reports import core
|
||||||
|
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
Hashable,
|
|
||||||
Iterable,
|
Iterable,
|
||||||
Iterator,
|
Iterator,
|
||||||
List,
|
List,
|
||||||
|
@ -46,6 +45,9 @@ from typing import (
|
||||||
Tuple,
|
Tuple,
|
||||||
Union,
|
Union,
|
||||||
)
|
)
|
||||||
|
from ..beancount_types import (
|
||||||
|
Sortable,
|
||||||
|
)
|
||||||
|
|
||||||
PROGNAME = 'reconcile-paypal'
|
PROGNAME = 'reconcile-paypal'
|
||||||
logger = logging.getLogger('conservancy_beancount.reconcile.paypal')
|
logger = logging.getLogger('conservancy_beancount.reconcile.paypal')
|
||||||
|
@ -164,7 +166,7 @@ class PayPalReconciler:
|
||||||
worst_problem = worst_problem or problems
|
worst_problem = worst_problem or problems
|
||||||
return worst_problem
|
return worst_problem
|
||||||
|
|
||||||
def sort_key(self) -> Hashable:
|
def sort_key(self) -> Sortable:
|
||||||
try:
|
try:
|
||||||
post = self.statement_posts[0]
|
post = self.statement_posts[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
|
|
@ -21,7 +21,6 @@ from typing import (
|
||||||
Callable,
|
Callable,
|
||||||
Collection,
|
Collection,
|
||||||
Dict,
|
Dict,
|
||||||
Hashable,
|
|
||||||
Iterable,
|
Iterable,
|
||||||
Iterator,
|
Iterator,
|
||||||
List,
|
List,
|
||||||
|
|
|
@ -27,7 +27,6 @@ from typing import (
|
||||||
Callable,
|
Callable,
|
||||||
Collection,
|
Collection,
|
||||||
Dict,
|
Dict,
|
||||||
Hashable,
|
|
||||||
Iterable,
|
Iterable,
|
||||||
Iterator,
|
Iterator,
|
||||||
List,
|
List,
|
||||||
|
|
|
@ -52,7 +52,6 @@ from typing import (
|
||||||
Collection,
|
Collection,
|
||||||
Dict,
|
Dict,
|
||||||
Generic,
|
Generic,
|
||||||
Hashable,
|
|
||||||
Iterable,
|
Iterable,
|
||||||
Iterator,
|
Iterator,
|
||||||
List,
|
List,
|
||||||
|
@ -70,6 +69,7 @@ from typing import (
|
||||||
from ..beancount_types import (
|
from ..beancount_types import (
|
||||||
MetaKey,
|
MetaKey,
|
||||||
MetaValue,
|
MetaValue,
|
||||||
|
Sortable,
|
||||||
)
|
)
|
||||||
|
|
||||||
OPENING_BALANCE_NAME = "OPENING BALANCE"
|
OPENING_BALANCE_NAME = "OPENING BALANCE"
|
||||||
|
@ -439,7 +439,7 @@ class Balances:
|
||||||
# Ensure the balance exists in the mapping
|
# Ensure the balance exists in the mapping
|
||||||
class_bals[key.classification]
|
class_bals[key.classification]
|
||||||
norm_func = normalize_amount_func(f'{account}:RootsOK')
|
norm_func = normalize_amount_func(f'{account}:RootsOK')
|
||||||
def sortkey(acct: data.Account) -> Hashable:
|
def sortkey(acct: data.Account) -> Sortable:
|
||||||
prefix, _, _ = acct.rpartition(':')
|
prefix, _, _ = acct.rpartition(':')
|
||||||
balance = norm_func(class_bals[acct])
|
balance = norm_func(class_bals[acct])
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -46,7 +46,6 @@ from typing import (
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
Dict,
|
Dict,
|
||||||
Hashable,
|
|
||||||
Iterable,
|
Iterable,
|
||||||
Iterator,
|
Iterator,
|
||||||
List,
|
List,
|
||||||
|
@ -61,6 +60,7 @@ from typing import (
|
||||||
cast,
|
cast,
|
||||||
)
|
)
|
||||||
from ..beancount_types import (
|
from ..beancount_types import (
|
||||||
|
Sortable,
|
||||||
Transaction,
|
Transaction,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -530,7 +530,7 @@ class ReportType(enum.IntFlag):
|
||||||
else:
|
else:
|
||||||
return cls.DEBIT_TRANSACTIONS
|
return cls.DEBIT_TRANSACTIONS
|
||||||
|
|
||||||
def _choices_sortkey(self) -> Hashable:
|
def _choices_sortkey(self) -> Sortable:
|
||||||
subtype, _, maintype = self.name.partition('_')
|
subtype, _, maintype = self.name.partition('_')
|
||||||
return (maintype, subtype)
|
return (maintype, subtype)
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ import sys
|
||||||
|
|
||||||
from typing import (
|
from typing import (
|
||||||
Dict,
|
Dict,
|
||||||
Hashable,
|
|
||||||
Iterable,
|
Iterable,
|
||||||
Iterator,
|
Iterator,
|
||||||
Mapping,
|
Mapping,
|
||||||
|
@ -41,6 +40,7 @@ from ..beancount_types import (
|
||||||
Error,
|
Error,
|
||||||
MetaKey,
|
MetaKey,
|
||||||
MetaValue,
|
MetaValue,
|
||||||
|
Sortable,
|
||||||
Transaction,
|
Transaction,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class AccountWithFund(NamedTuple):
|
||||||
account: data.Account
|
account: data.Account
|
||||||
fund: Optional[MetaValue]
|
fund: Optional[MetaValue]
|
||||||
|
|
||||||
def sortkey(self) -> Hashable:
|
def sortkey(self) -> Sortable:
|
||||||
account, fund = self
|
account, fund = self
|
||||||
return (
|
return (
|
||||||
0 if fund is None else 1,
|
0 if fund is None else 1,
|
||||||
|
|
|
@ -22,7 +22,6 @@ from beancount import loader as bc_loader
|
||||||
from beancount.parser import printer as bc_printer
|
from beancount.parser import printer as bc_printer
|
||||||
|
|
||||||
from typing import (
|
from typing import (
|
||||||
Hashable,
|
|
||||||
Optional,
|
Optional,
|
||||||
Sequence,
|
Sequence,
|
||||||
TextIO,
|
TextIO,
|
||||||
|
@ -31,6 +30,7 @@ from ..beancount_types import (
|
||||||
Directive,
|
Directive,
|
||||||
Entries,
|
Entries,
|
||||||
Errors,
|
Errors,
|
||||||
|
Sortable,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .. import cliutil
|
from .. import cliutil
|
||||||
|
@ -56,7 +56,7 @@ def parse_arguments(arglist: Optional[Sequence[str]]=None) -> argparse.Namespace
|
||||||
""")
|
""")
|
||||||
return parser.parse_args(arglist)
|
return parser.parse_args(arglist)
|
||||||
|
|
||||||
def entry_sorter(entry: Directive) -> Hashable:
|
def entry_sorter(entry: Directive) -> Sortable:
|
||||||
type_name = type(entry).__name__
|
type_name = type(entry).__name__
|
||||||
if type_name == 'Transaction':
|
if type_name == 'Transaction':
|
||||||
return (entry.date, type_name, entry.narration, entry.payee or '') # type:ignore[attr-defined]
|
return (entry.date, type_name, entry.narration, entry.payee or '') # type:ignore[attr-defined]
|
||||||
|
|
Loading…
Reference in a new issue