correct typing of the callable
This commit is contained in:
parent
85cb8526be
commit
b32404ca5f
1 changed files with 6 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from typing import Callable
|
from typing import Callable, Union, Dict
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
|
|
@ -13,7 +13,9 @@ fiat_currencies = json.load(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
exchange_rate_providers = {
|
exchange_rate_providers: dict[
|
||||||
|
str, dict[str, Union[str, Callable[[dict, dict], str]]]
|
||||||
|
] = {
|
||||||
"bitfinex": {
|
"bitfinex": {
|
||||||
"name": "Bitfinex",
|
"name": "Bitfinex",
|
||||||
"domain": "bitfinex.com",
|
"domain": "bitfinex.com",
|
||||||
|
|
@ -75,6 +77,6 @@ async def fetch_fiat_exchange_rate(currency: str, provider: str):
|
||||||
data = r.json()
|
data = r.json()
|
||||||
|
|
||||||
getter = exchange_rate_providers[provider]["getter"]
|
getter = exchange_rate_providers[provider]["getter"]
|
||||||
# TODO: mypy typing does not work out
|
if callable(getter):
|
||||||
rate = float(getter(data, replacements)) # type: ignore
|
rate = float(getter(data, replacements))
|
||||||
return rate
|
return rate
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue