1
0

Improved type annotations

This commit is contained in:
Jon Michael Aanes 2024-07-20 20:21:50 +02:00
parent 1903d55038
commit 15386f0b4d
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
6 changed files with 19 additions and 12 deletions

View File

@ -25,6 +25,8 @@ __all__ = [
'defi_kucoin',
'defi_partisia_blockchain',
'investbank_nordnet',
'__version__',
]
from . import defi_kraken, defi_kucoin, defi_partisia_blockchain, investbank_nordnet
from ._version import __version__

View File

@ -10,7 +10,7 @@ from fin_defs import Asset
@enforce_typing.enforce_types
@dataclasses.dataclass
@dataclasses.dataclass(frozen=True)
class Depo(abc.ABC):
"""A depository tracking some amount of assets.
@ -38,7 +38,7 @@ class Depo(abc.ABC):
@enforce_typing.enforce_types
@dataclasses.dataclass
@dataclasses.dataclass(frozen=True)
class DepoSingle(Depo):
"""Base level of depository."""
@ -52,7 +52,7 @@ class DepoSingle(Depo):
@enforce_typing.enforce_types
@dataclasses.dataclass
@dataclasses.dataclass(frozen=True)
class DepoGroup(Depo):
"""Nested depository."""

View File

@ -7,6 +7,7 @@ import json
import logging
from collections.abc import Mapping
from decimal import Decimal
from typing import Any
import fin_defs
import requests
@ -55,9 +56,9 @@ class PbcClient:
def get_json(
self,
url: str,
data: Mapping[str, str] = frozendict(),
data: Mapping[str, Any] = frozendict(),
method='POST',
) -> tuple[dict, datetime.datetime]:
) -> tuple[Any, datetime.datetime]:
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
@ -80,10 +81,10 @@ class PbcClient:
raise Exception(msg)
return (json_data, date)
def determine_coins(self) -> list[dict[str, str]]:
def determine_coins(self) -> list[dict[str, Any]]:
data: dict = {'path': []}
url = URL_ACCOUNT_PLUGIN_GLOBAL.format(
url: str = URL_ACCOUNT_PLUGIN_GLOBAL.format(
hostname=HOSTNAME,
shard='',
)

View File

@ -11,7 +11,9 @@ I am grateful for his pioneering work.
import datetime
import logging
from collections.abc import Mapping
from decimal import Decimal
from typing import Any
import fin_defs
import requests
@ -41,7 +43,7 @@ def asset_from_instrument_json(json) -> fin_defs.Asset | None:
return fin_defs.Stock(symbol, fin_defs.EXCHANGES_BY_IDS[exchange_id])
EMPTY_DICT: dict[str, str | int] = frozendict()
EMPTY_DICT: Mapping[str, str | int] = frozendict()
class NordnetDepoFetcher(DepoFetcher):
@ -66,7 +68,7 @@ class NordnetDepoFetcher(DepoFetcher):
self.password: str = self.assert_param('password', str, password)
self.is_logged_in = False
def _get_json(self, url: str, params: dict[str, str | int] = EMPTY_DICT) -> dict:
def _get_json(self, url: str, params: Mapping[str, str | int] = EMPTY_DICT) -> Any:
if not url.startswith(API_ROOT):
msg = f'Given url must be located below API ROOT: {url}'
raise ValueError(msg)
@ -80,7 +82,7 @@ class NordnetDepoFetcher(DepoFetcher):
response.raise_for_status()
return json
def login(self):
def login(self) -> None:
"""Performs authentication with the login server if not already logged
in. Does not need to be manually called; most methods that require this
information will do it themselves.

View File

@ -1,7 +1,7 @@
import pytest
import requests
from fin_depo import data, defi_kraken
from fin_depo import defi_kraken
from . import secrets
@ -10,6 +10,7 @@ needs_secrets = pytest.mark.skipif(
reason='Secret kraken_USERNAME required',
)
@needs_secrets
def test_get_depo():
session = requests.Session()

View File

@ -1,7 +1,7 @@
import pytest
import requests
from fin_depo import data, defi_kucoin
from fin_depo import defi_kucoin
from . import secrets
@ -10,6 +10,7 @@ needs_secrets = pytest.mark.skipif(
reason='Secret kucoin_USERNAME required',
)
@needs_secrets
def test_get_depo():
session = requests.Session()