From d9d649d430d81188b0c1b5b0155935c0e5ac14e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20Marussy?= Date: Mon, 25 Jan 2021 01:55:43 +0100 Subject: Fix type errors --- beancount_extras_kris7t/importers/transferwise/__main__.py | 2 +- beancount_extras_kris7t/importers/transferwise/client.py | 12 +++++++----- .../importers/transferwise/transferwise_json.py | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) (limited to 'beancount_extras_kris7t/importers/transferwise') diff --git a/beancount_extras_kris7t/importers/transferwise/__main__.py b/beancount_extras_kris7t/importers/transferwise/__main__.py index e25580d..4ac2058 100644 --- a/beancount_extras_kris7t/importers/transferwise/__main__.py +++ b/beancount_extras_kris7t/importers/transferwise/__main__.py @@ -4,7 +4,7 @@ Importer for Transferwise API transaction history. __copyright__ = 'Copyright (c) 2020 Kristóf Marussy ' __license__ = 'GNU GPLv2' -from importers.transferwise.client import main +from beancount_extras_kris7t.importers.transferwise.client import main if __name__ == '__main__': diff --git a/beancount_extras_kris7t/importers/transferwise/client.py b/beancount_extras_kris7t/importers/transferwise/client.py index a4b6629..5198122 100644 --- a/beancount_extras_kris7t/importers/transferwise/client.py +++ b/beancount_extras_kris7t/importers/transferwise/client.py @@ -25,8 +25,8 @@ def _parse_date_arg(date_str: str) -> dt.date: def _import_config(config_path: str) -> Importer: import runpy - config = runpy.run_path(config_path) - importer = config['TRANSFERWISE_CONFIG'] # type: ignore + config = runpy.run_path(config_path) # type: ignore + importer = config['TRANSFERWISE_CONFIG'] if isinstance(importer, Importer): LOG.info('Loaded configuration from %s', config_path) return importer @@ -65,7 +65,7 @@ def _get_last_transaction_date(ledger_path: str, skip_references: Set[str]) -> O def _get_date_range(from_date: Optional[dt.date], to_date: dt.date, ledger_path: Optional[str]) -> Tuple[dt.date, dt.date, Set[str]]: - skip_references = set() + skip_references: Set[str] = set() if not from_date and ledger_path: from_date = _get_last_transaction_date(ledger_path, skip_references) if not from_date: @@ -79,6 +79,7 @@ def _get_secrets(importer: Importer, proxy_uri: Optional[str]) -> Tuple[str, Optional[str]]: import urllib.parse + uri_parts: Optional[urllib.parse.SplitResult] if proxy_uri: uri_parts = urllib.parse.urlsplit(proxy_uri) else: @@ -122,7 +123,7 @@ def _get_secrets(importer: Importer, proxy_uri = uri else: LOG.info('No proxy password secret was found in SecretService') - assert api_key # Make pyright happy + assert api_key # Make mypy happy return api_key, proxy_uri @@ -141,8 +142,9 @@ def _fetch_statements(importer: Importer, uri_prefix = f'https://api.transferwise.com/v3/profiles/{importer.profile_id}/' + \ f'borderless-accounts/{importer.borderless_account_id}/statement.json' + \ f'?intervalStart={from_time_str}&intervalEnd={to_time_str}&type=COMPACT¤cy=' + beancount_version = beancount.__version__ # type: ignore # noqa: unused-type-ignore headers = { - 'User-Agent': f'Beancount {beancount.__version__} Transferwise importer {__copyright__}', + 'User-Agent': f'Beancount {beancount_version} Transferwise importer {__copyright__}', 'Authorization': f'Bearer {api_key}', } proxy_dict: Dict[str, str] = {} diff --git a/beancount_extras_kris7t/importers/transferwise/transferwise_json.py b/beancount_extras_kris7t/importers/transferwise/transferwise_json.py index c42de90..68ddc6d 100644 --- a/beancount_extras_kris7t/importers/transferwise/transferwise_json.py +++ b/beancount_extras_kris7t/importers/transferwise/transferwise_json.py @@ -211,6 +211,8 @@ class Row(utils.Row): # Also add the "fudge" amounts to the fees generated by rounding currency conversions. all_fees = Inventory() all_fees.add_inventory(self._fees) + if not self.postings: + raise InvalidEntry('Trying to create transaction without postings') for acc, assigned_units in self.postings: for conversion in self._conversions: units, price, fudge = conversion.get_fraction( -- cgit v1.2.3