Skip to content

Commit 05537ba

Browse files
authored
Enh/code revamp 2 (#23)
* Create and use Country common entity * Enforce kwargs usage with all mixins
1 parent 1dbbc4a commit 05537ba

File tree

11 files changed

+40
-74
lines changed

11 files changed

+40
-74
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from typing import Final
2+
3+
from .country import Country
4+
5+
__all__: Final[list[str]] = [
6+
"Country"
7+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Country:
2+
"""Country entity."""
3+
4+
def __init__(self, code: str, name: str) -> None:
5+
"""Initializes a new Country."""
6+
self._code = code
7+
self._name = name
8+
9+
@property
10+
def code(self) -> str | None:
11+
"""The country's two-letter ISO 3166-1 alpha-2 code."""
12+
return self._code
13+
14+
@property
15+
def name(self) -> str | None:
16+
"""The name of the country."""
17+
return self._name

src/abstract_api/image_processing/strategies/_mixins/crop_mode_mixin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ class CropModeMixin(_Base):
3535

3636
def __init__(
3737
self,
38+
*,
3839
crop_mode: CropMode | str | None = None,
39-
*args,
4040
**kwargs
4141
) -> None:
4242
"""Initializes a new instance."""
43-
super().__init__(*args, **kwargs)
43+
super().__init__(**kwargs)
4444

4545
if crop_mode is not None:
4646
if isinstance(crop_mode, str):

src/abstract_api/image_processing/strategies/_mixins/height_mixin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
class HeightMixin(_Base):
1212
"""Height mixin."""
13-
def __init__(self, height: int, *args, **kwargs) -> None:
13+
def __init__(self, *, height: int, **kwargs) -> None:
1414
"""Initializes a new instance."""
15-
super().__init__(*args, **kwargs)
15+
super().__init__(**kwargs)
1616
self._height = height
1717

1818
def json(self) -> dict[str, int | str]:

src/abstract_api/image_processing/strategies/_mixins/width_mixin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
class WidthMixin(_Base):
1212
"""Width mixin."""
13-
def __init__(self, width: int, *args, **kwargs) -> None:
13+
def __init__(self, *, width: int, **kwargs) -> None:
1414
"""Initializes a new instance."""
15-
super().__init__(*args, **kwargs)
15+
super().__init__(**kwargs)
1616
self._width = width
1717

1818
def json(self) -> dict[str, int | str]:

src/abstract_api/image_processing/strategies/crop/crop.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ def __init__(
3838
scale: int | None = None,
3939
x: int | None = None,
4040
y: int | None = None,
41-
*args,
4241
**kwargs
4342
) -> None:
4443
"""Initializes a new Crop instance."""
45-
super().__init__(*args, **kwargs)
44+
super().__init__(**kwargs)
4645
self._scale = scale
4746
self._x = x
4847
self._y = y

src/abstract_api/image_processing/strategies/fill.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ class Fill(HeightMixin, WidthMixin, BaseStrategy):
1010
The default background color is black.
1111
"""
1212

13-
def __init__(
14-
self,
15-
background: str | None = None,
16-
*args,
17-
**kwargs
18-
) -> None:
13+
def __init__(self, background: str | None = None, **kwargs) -> None:
1914
"""Initialize a new Square instance."""
20-
super().__init__(*args, **kwargs)
15+
super().__init__(**kwargs)
2116
self._background = background
2217

2318
def json(self) -> dict[str, int | str]:

src/abstract_api/image_processing/strategies/square.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Square(BaseStrategy):
99

1010
def __init__(self, size: int) -> None:
1111
"""Initialize a new Square instance."""
12+
super().__init__()
1213
self._size = size
1314

1415
def json(self) -> dict[str, int | str]:

src/abstract_api/phone_validation/phone_validation_response.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import requests
22

33
from ..core.bases import JSONResponse
4+
from ..core.common_entities import Country as CommonCountry
45
from ..core.mixins import NestedEntitiesMixin
56
from .response_fields import RESPONSE_FIELDS
67

@@ -32,25 +33,14 @@ def local(self) -> str:
3233
return self._local
3334

3435

35-
class Country:
36+
class Country(CommonCountry):
3637
"""Country entity in phone validation response."""
3738

38-
def __init__(self, code: str, name: str, prefix: str) -> None:
39+
def __init__(self, prefix: str, **kwargs) -> None:
3940
"""Initializes a new Country."""
40-
self._code = code
41-
self._name = name
41+
super().__init__(**kwargs)
4242
self._prefix = prefix
4343

44-
@property
45-
def code(self) -> str | None:
46-
"""The country's two-letter ISO 3166-1 alpha-2 code."""
47-
return self._code
48-
49-
@property
50-
def name(self) -> str | None:
51-
"""The name of the country in which the phone number is registered."""
52-
return self._name
53-
5444
@property
5545
def prefix(self) -> str | None:
5646
"""The country's calling code prefix."""

src/abstract_api/vat/vat_calculation_response.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,11 @@
11
import requests
22

33
from ..core.bases import JSONResponse
4+
from ..core.common_entities import Country
45
from ..core.mixins import NestedEntitiesMixin
56
from .response_fields.calculation import CALCULATION_RESPONSE_FIELDS
67

78

8-
class Country:
9-
"""Country entity in VAT calculation response."""
10-
11-
def __init__(self, code: str, name: str) -> None:
12-
"""Initializes a new Country."""
13-
self._code = code
14-
self._name = name
15-
16-
@property
17-
def code(self) -> str | None:
18-
"""The two-letter ISO 3166-1 alpha-2 code of the country.
19-
20-
It is the code of the country in which the transaction takes place.
21-
"""
22-
return self._code
23-
24-
@property
25-
def name(self) -> str | None:
26-
"""The name of the country the VAT is being calculated from."""
27-
return self._name
28-
29-
309
class VATCalculationResponse(NestedEntitiesMixin, JSONResponse):
3110
"""VAT calculation service response."""
3211

0 commit comments

Comments
 (0)