Skip to content

Commit 68aba38

Browse files
author
Tom Hendrikx
committed
Enable mypy 'check_untyped_defs'
This uncovers various issues with the implementation of `get_resource_class()`. Now we have mypy passing and the code should work in theory, but the only place where this method is used (in `ObjectList`), already shows clearly that the current approach won't work. We need to rethink the way ObjectList works, and hopefully get rid of `get_resource_class()` entirely.
1 parent fa703e1 commit 68aba38

File tree

7 files changed

+42
-12
lines changed

7 files changed

+42
-12
lines changed

mollie/api/objects/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
from typing import TYPE_CHECKING, Any
2+
13
from ..error import EmbedNotFound
24

5+
if TYPE_CHECKING:
6+
from ..client import Client
7+
38

49
class ObjectBase(dict):
510
def __init__(self, data, client):
@@ -42,5 +47,5 @@ def get_object_name(cls):
4247
return f"{name}s"
4348

4449
@classmethod
45-
def get_resource_class(cls, client):
50+
def get_resource_class(cls, client: "Client", **kwargs: Any) -> Any:
4651
raise NotImplementedError # pragma: no cover

mollie/api/objects/capture.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
from typing import TYPE_CHECKING, Any
2+
13
from .base import ObjectBase
24

5+
if TYPE_CHECKING:
6+
from ..client import Client
7+
from ..resources import PaymentCaptures
8+
39

410
class Capture(ObjectBase):
511
@classmethod
6-
def get_resource_class(cls, client):
12+
def get_resource_class(cls, client: "Client", **kwargs: Any) -> "PaymentCaptures":
713
from ..resources import PaymentCaptures
814

9-
return PaymentCaptures(client)
15+
payment = kwargs["payment"]
16+
return PaymentCaptures(client, payment)
1017

1118
@property
1219
def id(self):
@@ -50,9 +57,10 @@ def get_shipment(self):
5057
url = self._get_link("shipment")
5158
if url:
5259
from ..resources import OrderShipments
60+
from .order import Order
5361

54-
# We fake the order object here, since it is not used by from_url()
55-
return OrderShipments(self.client, order=None).from_url(url)
62+
order = Order({}, self.client)
63+
return OrderShipments(self.client, order).from_url(url)
5664

5765
def get_settlement(self):
5866
"""Return the settlement for this capture."""

mollie/api/objects/mandate.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
from typing import TYPE_CHECKING, Any
2+
13
from .base import ObjectBase
24

5+
if TYPE_CHECKING:
6+
from ..client import Client
7+
from ..resources import CustomerMandates
8+
39

410
class Mandate(ObjectBase):
511
@classmethod
6-
def get_resource_class(cls, client):
12+
def get_resource_class(cls, client: "Client", **kwargs: Any) -> "CustomerMandates":
713
from ..resources import CustomerMandates
814

9-
return CustomerMandates(client)
15+
customer = kwargs["customer"]
16+
return CustomerMandates(client, customer)
1017

1118
STATUS_PENDING = "pending"
1219
STATUS_VALID = "valid"

mollie/api/objects/order_line.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
from typing import TYPE_CHECKING, Any
2+
13
from .base import ObjectBase
24

5+
if TYPE_CHECKING:
6+
from ..client import Client
7+
from ..resources import OrderLines
8+
39

410
class OrderLine(ObjectBase):
511
@classmethod
6-
def get_resource_class(cls, client):
12+
def get_resource_class(cls, client: "Client", **kwargs: Any) -> "OrderLines":
713
from ..resources import OrderLines
814

9-
return OrderLines(client)
15+
order = kwargs["order"]
16+
return OrderLines(client, order)
1017

1118
STATUS_CREATED = "created"
1219
STATUS_AUTHORIZED = "authorized"

mollie/api/objects/payment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ def get_subscription(self):
213213
if url:
214214
from ..resources import CustomerSubscriptions
215215

216-
return CustomerSubscriptions(self.client, customer=None).from_url(url)
216+
customer = Customer({}, self.client)
217+
return CustomerSubscriptions(self.client, customer).from_url(url)
217218

218219
def get_customer(self):
219220
"""Return the customer for this payment."""

mollie/api/objects/subscription.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
class Subscription(ObjectBase):
88
@classmethod
9-
def get_resource_class(cls, client):
9+
def get_resource_class(cls, client, **kwargs):
1010
from ..resources import CustomerSubscriptions
1111

12-
return CustomerSubscriptions(client)
12+
customer = kwargs["customer"]
13+
return CustomerSubscriptions(client, customer)
1314

1415
STATUS_ACTIVE = "active"
1516
STATUS_PENDING = "pending" # Waiting for a valid mandate.

mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ no_implicit_optional = True
66
strict_equality = True
77
strict_concatenate = True
88
disallow_incomplete_defs = True
9+
check_untyped_defs = True
910

1011
[mypy-requests_oauthlib.*]
1112
# requests-oauthlib-1.3.1 has no types yet, but: https://github.com/requests/requests-oauthlib/issues/428

0 commit comments

Comments
 (0)