Skip to content

Commit 121fecd

Browse files
authored
Enh/type hints revisit (#21)
* Remove duplicated type hints in subclasses * revamp type hints
1 parent 4a7ff89 commit 121fecd

File tree

22 files changed

+38
-30
lines changed

22 files changed

+38
-30
lines changed

src/abstract_api/avatars/avatars.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class Avatars(BaseService[AvatarsResponse]):
1111
Attributes:
1212
_subdomain: Avatars service subdomain.
1313
"""
14-
_subdomain: str = "avatars"
14+
_subdomain = "avatars"
1515

1616
def create(
1717
self,
18-
name,
18+
name: str,
1919
image_size: int | None = None,
2020
image_format: str | None = None,
2121
font_size: float | None = None,

src/abstract_api/company_enrichment/company_enrichment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CompanyEnrichment(
1717
Attributes:
1818
_subdomain: Company enrichment service subdomain.
1919
"""
20-
_subdomain: str = "companyenrichment"
20+
_subdomain = "companyenrichment"
2121
_response_fields = RESPONSE_FIELDS
2222

2323
def check(

src/abstract_api/core/bases/_base_response.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@ def body(self) -> bytes:
2424

2525

2626
class BaseResponse(ABC):
27-
"""Base Abstract API service response."""
27+
"""Base Abstract API service response.
28+
29+
Attributes:
30+
_meta_class: Class (type) of meta.
31+
"""
2832
_meta_class: ClassVar[Type[BaseResponseMeta]]
29-
meta: BaseResponseMeta
3033

3134
def __init__(self, response: requests.models.Response) -> None:
3235
"""Initialize a new BaseResponse."""
33-
self.meta = self._meta_class(response)
36+
self._meta: BaseResponseMeta = self._meta_class(response)
37+
38+
@property
39+
def meta(self) -> BaseResponseMeta:
40+
"""Meta data about response."""
41+
return self._meta

src/abstract_api/core/bases/base_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, api_key: str) -> None:
3434
Args:
3535
api_key: API key to be used to authenticate with AbstractAPI.
3636
"""
37-
self._api_key = api_key
37+
self._api_key: str = api_key
3838

3939
def _service_url(self, action: str = "") -> str:
4040
"""Builds and returns an API URL for a service using its subdomain.

src/abstract_api/core/bases/file_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FileResponseMeta(BaseResponseMeta):
1111

1212
class FileResponse(BaseResponse):
1313
"""TODO."""
14-
_meta_class: ClassVar[Type] = FileResponseMeta
14+
_meta_class: ClassVar[Type[FileResponseMeta]] = FileResponseMeta
1515
meta: FileResponseMeta
1616

1717
def __init__(self, response: requests.models.Response) -> None:

src/abstract_api/core/bases/json_response.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING, Any, ClassVar, Type, Union
1+
from typing import TYPE_CHECKING, Any, ClassVar, Type
22

33
import requests
44

@@ -17,15 +17,15 @@ def __init__(self, response: requests.models.Response) -> None:
1717
self._body_json = None
1818

1919
@property
20-
def body_json(self) -> Union[dict[str, Any], list[dict[str, Any]]]:
20+
def body_json(self) -> dict[str, Any] | list[dict[str, Any]]:
2121
"""JSON representation of response body returned from API request."""
2222
return self._body_json
2323

2424

2525
class JSONResponse(BaseResponse):
2626
"""TODO."""
2727
_response_fields: frozenset[str]
28-
_meta_class: ClassVar[Type] = JSONResponseMeta
28+
_meta_class: ClassVar[Type[JSONResponseMeta]] = JSONResponseMeta
2929
meta: JSONResponseMeta
3030

3131
def _init_response_field(self, field: str, value: Any) -> None:
@@ -37,7 +37,7 @@ def __init__(
3737
response: requests.models.Response,
3838
response_fields: frozenset[str],
3939
list_response: bool = False
40-
):
40+
) -> None:
4141
"""TODO."""
4242
super().__init__(response)
4343
self._response_fields = response_fields

src/abstract_api/email_validation/email_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class EmailValidation(BaseService[EmailValidationResponse]):
1010
Attributes:
1111
_subdomain: Email validation service subdomain.
1212
"""
13-
_subdomain: str = "emailvalidation"
13+
_subdomain = "emailvalidation"
1414

1515
def check(
1616
self,

src/abstract_api/email_validation/email_validation_response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, ClassVar
1+
from typing import Any
22

33
import requests
44

@@ -9,7 +9,7 @@
99
class EmailValidationResponse(JSONResponse):
1010
"""Email validation service response."""
1111

12-
_complex_bool_fields: ClassVar[frozenset[str]] = frozenset({
12+
_complex_bool_fields = frozenset({
1313
"is_valid_format",
1414
"is_free_email",
1515
"is_disposable_email",

src/abstract_api/exchange_rates/exchange_rates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ExchangeRates(BaseService):
1616
Attributes:
1717
_subdomain: Exchange rates service subdomain.
1818
"""
19-
_subdomain: str = "exchange-rates"
19+
_subdomain = "exchange-rates"
2020

2121
@staticmethod
2222
def _target_as_param(target: Iterable[str] | None = None) -> str | None:

src/abstract_api/holidays/holidays.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Holidays(BaseService[HolidaysResponse]):
1111
Attributes:
1212
_subdomain: Holidays service subdomain.
1313
"""
14-
_subdomain: str = "holidays"
14+
_subdomain = "holidays"
1515

1616
def lookup(
1717
self,

0 commit comments

Comments
 (0)