Skip to content

Commit

Permalink
mypy'ed
Browse files Browse the repository at this point in the history
  • Loading branch information
matin committed May 28, 2020
1 parent 3f99419 commit 671c162
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cuenca/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
WhatsappTransfer,
]
for resource_cls in resource_classes:
RESOURCES[resource_cls._resource] = resource_cls
RESOURCES[resource_cls._resource] = resource_cls # type: ignore
4 changes: 2 additions & 2 deletions cuenca/resources/card_transactions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import lru_cache
from typing import ClassVar, List
from typing import ClassVar, List, cast

from pydantic.dataclasses import dataclass

Expand All @@ -23,7 +23,7 @@ class CardTransaction(Transaction):
def related_card_transactions(self) -> List['CardTransaction']:
related = []
for uri in self.related_card_transaction_uris:
related.append(retrieve_uri(uri))
related.append(cast('CardTransaction', retrieve_uri(uri)))
return related

def __hash__(self) -> int:
Expand Down
4 changes: 2 additions & 2 deletions cuenca/resources/deposits.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import lru_cache
from typing import ClassVar
from typing import ClassVar, cast

from ..types import DepositNetwork
from .accounts import Account
Expand All @@ -17,4 +17,4 @@ class Deposit(Transaction, Cacheable):
@property # type: ignore
@lru_cache()
def source(self) -> Account:
return retrieve_uri(self.source_uri)
return cast(Account, retrieve_uri(self.source_uri))
9 changes: 6 additions & 3 deletions cuenca/resources/resources.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import Dict
from typing import Dict, cast

from .base import Retrievable

Expand All @@ -8,5 +8,8 @@


def retrieve_uri(uri: str) -> Retrievable:
resource, id_ = ENDPOINT_RE.match(uri).groups()
return RESOURCES[resource].retrieve(id_)
m = ENDPOINT_RE.match(uri)
if not m:
raise ValueError(f'uri is not a valid format: {uri}')
resource, id_ = m.groups()
return cast(Retrievable, RESOURCES[resource].retrieve(id_))
4 changes: 2 additions & 2 deletions cuenca/resources/whatsapp_transfers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime as dt
from functools import lru_cache
from typing import ClassVar, Optional
from typing import ClassVar, Optional, cast

from pydantic.dataclasses import dataclass

Expand Down Expand Up @@ -30,7 +30,7 @@ def destination(self) -> Optional[Account]:
if self.destination_uri is None:
dest = None
else:
dest = retrieve_uri(self.destination_uri)
dest = cast(Account, retrieve_uri(self.destination_uri))
return dest

def __hash__(self):
Expand Down

0 comments on commit 671c162

Please sign in to comment.