diff options
author | 2021-01-25 01:55:43 +0100 | |
---|---|---|
committer | 2021-01-25 01:55:43 +0100 | |
commit | d9d649d430d81188b0c1b5b0155935c0e5ac14e2 (patch) | |
tree | b02d1ab8aa43a0f2aeb79e91eeb340b5de27e718 /beancount_extras_kris7t/importers/transferwise | |
parent | Make Pyright happy by importing load_doc directly (diff) | |
download | beancount-extras-kris7t-d9d649d430d81188b0c1b5b0155935c0e5ac14e2.tar.gz beancount-extras-kris7t-d9d649d430d81188b0c1b5b0155935c0e5ac14e2.tar.zst beancount-extras-kris7t-d9d649d430d81188b0c1b5b0155935c0e5ac14e2.zip |
Fix type errors
Diffstat (limited to 'beancount_extras_kris7t/importers/transferwise')
3 files changed, 10 insertions, 6 deletions
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. | |||
4 | __copyright__ = 'Copyright (c) 2020 Kristóf Marussy <kristof@marussy.com>' | 4 | __copyright__ = 'Copyright (c) 2020 Kristóf Marussy <kristof@marussy.com>' |
5 | __license__ = 'GNU GPLv2' | 5 | __license__ = 'GNU GPLv2' |
6 | 6 | ||
7 | from importers.transferwise.client import main | 7 | from beancount_extras_kris7t.importers.transferwise.client import main |
8 | 8 | ||
9 | 9 | ||
10 | if __name__ == '__main__': | 10 | 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: | |||
25 | def _import_config(config_path: str) -> Importer: | 25 | def _import_config(config_path: str) -> Importer: |
26 | import runpy | 26 | import runpy |
27 | 27 | ||
28 | config = runpy.run_path(config_path) | 28 | config = runpy.run_path(config_path) # type: ignore |
29 | importer = config['TRANSFERWISE_CONFIG'] # type: ignore | 29 | importer = config['TRANSFERWISE_CONFIG'] |
30 | if isinstance(importer, Importer): | 30 | if isinstance(importer, Importer): |
31 | LOG.info('Loaded configuration from %s', config_path) | 31 | LOG.info('Loaded configuration from %s', config_path) |
32 | return importer | 32 | return importer |
@@ -65,7 +65,7 @@ def _get_last_transaction_date(ledger_path: str, skip_references: Set[str]) -> O | |||
65 | def _get_date_range(from_date: Optional[dt.date], | 65 | def _get_date_range(from_date: Optional[dt.date], |
66 | to_date: dt.date, | 66 | to_date: dt.date, |
67 | ledger_path: Optional[str]) -> Tuple[dt.date, dt.date, Set[str]]: | 67 | ledger_path: Optional[str]) -> Tuple[dt.date, dt.date, Set[str]]: |
68 | skip_references = set() | 68 | skip_references: Set[str] = set() |
69 | if not from_date and ledger_path: | 69 | if not from_date and ledger_path: |
70 | from_date = _get_last_transaction_date(ledger_path, skip_references) | 70 | from_date = _get_last_transaction_date(ledger_path, skip_references) |
71 | if not from_date: | 71 | if not from_date: |
@@ -79,6 +79,7 @@ def _get_secrets(importer: Importer, | |||
79 | proxy_uri: Optional[str]) -> Tuple[str, Optional[str]]: | 79 | proxy_uri: Optional[str]) -> Tuple[str, Optional[str]]: |
80 | import urllib.parse | 80 | import urllib.parse |
81 | 81 | ||
82 | uri_parts: Optional[urllib.parse.SplitResult] | ||
82 | if proxy_uri: | 83 | if proxy_uri: |
83 | uri_parts = urllib.parse.urlsplit(proxy_uri) | 84 | uri_parts = urllib.parse.urlsplit(proxy_uri) |
84 | else: | 85 | else: |
@@ -122,7 +123,7 @@ def _get_secrets(importer: Importer, | |||
122 | proxy_uri = uri | 123 | proxy_uri = uri |
123 | else: | 124 | else: |
124 | LOG.info('No proxy password secret was found in SecretService') | 125 | LOG.info('No proxy password secret was found in SecretService') |
125 | assert api_key # Make pyright happy | 126 | assert api_key # Make mypy happy |
126 | return api_key, proxy_uri | 127 | return api_key, proxy_uri |
127 | 128 | ||
128 | 129 | ||
@@ -141,8 +142,9 @@ def _fetch_statements(importer: Importer, | |||
141 | uri_prefix = f'https://api.transferwise.com/v3/profiles/{importer.profile_id}/' + \ | 142 | uri_prefix = f'https://api.transferwise.com/v3/profiles/{importer.profile_id}/' + \ |
142 | f'borderless-accounts/{importer.borderless_account_id}/statement.json' + \ | 143 | f'borderless-accounts/{importer.borderless_account_id}/statement.json' + \ |
143 | f'?intervalStart={from_time_str}&intervalEnd={to_time_str}&type=COMPACT¤cy=' | 144 | f'?intervalStart={from_time_str}&intervalEnd={to_time_str}&type=COMPACT¤cy=' |
145 | beancount_version = beancount.__version__ # type: ignore # noqa: unused-type-ignore | ||
144 | headers = { | 146 | headers = { |
145 | 'User-Agent': f'Beancount {beancount.__version__} Transferwise importer {__copyright__}', | 147 | 'User-Agent': f'Beancount {beancount_version} Transferwise importer {__copyright__}', |
146 | 'Authorization': f'Bearer {api_key}', | 148 | 'Authorization': f'Bearer {api_key}', |
147 | } | 149 | } |
148 | proxy_dict: Dict[str, str] = {} | 150 | 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): | |||
211 | # Also add the "fudge" amounts to the fees generated by rounding currency conversions. | 211 | # Also add the "fudge" amounts to the fees generated by rounding currency conversions. |
212 | all_fees = Inventory() | 212 | all_fees = Inventory() |
213 | all_fees.add_inventory(self._fees) | 213 | all_fees.add_inventory(self._fees) |
214 | if not self.postings: | ||
215 | raise InvalidEntry('Trying to create transaction without postings') | ||
214 | for acc, assigned_units in self.postings: | 216 | for acc, assigned_units in self.postings: |
215 | for conversion in self._conversions: | 217 | for conversion in self._conversions: |
216 | units, price, fudge = conversion.get_fraction( | 218 | units, price, fudge = conversion.get_fraction( |