Skip to content

Commit aa5eb62

Browse files
committed
solve docstring errors for ruff
1 parent c9fb88f commit aa5eb62

24 files changed

Lines changed: 169 additions & 9 deletions

amazon_paapi/api.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __init__(
4141
throttling: float = 1,
4242
**kwargs,
4343
) -> None:
44+
"""Initialize the Amazon API client with the provided credentials."""
4445
self._key = key
4546
self._secret = secret
4647
self._last_query_time = time.time() - throttling
@@ -142,9 +143,11 @@ def search_items(
142143
sort_by: models.SortBy = None,
143144
**kwargs,
144145
) -> models.SearchResult:
145-
"""Searches for items on Amazon based on a search query. At least one of the
146-
following parameters should be specified: ``keywords``, ``actor``, ``artist``,
147-
``author``, ``brand``, ``title``, ``browse_node_id`` or ``search_index``.
146+
"""Search for items on Amazon based on a search query.
147+
148+
At least one of the following parameters should be specified: ``keywords``,
149+
``actor``, ``artist``, ``author``, ``brand``, ``title``, ``browse_node_id``
150+
or ``search_index``.
148151
149152
Args:
150153
item_count (``int``, optional): Number of items returned. Should be between
@@ -243,8 +246,10 @@ def get_variations(
243246
merchant: models.Merchant = None,
244247
**kwargs,
245248
) -> models.VariationsResult:
246-
"""Returns a set of items that are the same product, but differ according to a
247-
consistent theme, for example size and color. A variation is a child ASIN.
249+
"""Return a set of items that are the same product but differ by theme.
250+
251+
Items can differ by size, color, or other variation attributes.
252+
A variation is a child ASIN.
248253
249254
Args:
250255
asin (``str``): One item, using ASIN or product URL.
@@ -299,8 +304,9 @@ def get_browse_nodes(
299304
languages_of_preference: Optional[List[str]] = None,
300305
**kwargs,
301306
) -> List[models.BrowseNode]:
302-
"""Returns the specified browse node's information like name, children and
303-
ancestors.
307+
"""Return the specified browse node's information.
308+
309+
Information includes name, children, and ancestors.
304310
305311
Args:
306312
browse_node_ids (``list[str]``): List of browse node ids. A browse node id
@@ -333,6 +339,7 @@ def get_browse_nodes(
333339
return requests.get_browse_nodes_response(self, request)
334340

335341
def _throttle(self) -> None:
342+
"""Wait for the throttling interval to elapse since the last API call."""
336343
wait_time = self.throttling - (time.time() - self._last_query_time)
337344
if wait_time > 0:
338345
time.sleep(wait_time)

amazon_paapi/errors/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Custom exceptions for the Amazon Product Advertising API."""
2+
13
from .exceptions import (
24
AmazonError,
35
AsinNotFound,

amazon_paapi/errors/exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ class AmazonError(Exception):
55
"""Common base class for all Amazon API exceptions."""
66

77
def __init__(self, reason: str) -> None:
8+
"""Initialize the exception with a reason message."""
89
super().__init__()
910
self.reason = reason
1011

1112
def __str__(self) -> str:
13+
"""Return the string representation of the exception."""
1214
return self.reason
1315

1416

amazon_paapi/helpers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Helper modules for Amazon PAAPI requests and responses."""

amazon_paapi/helpers/arguments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ def get_items_ids(items: Union[str, List[str]]) -> List[str]:
3131

3232

3333
def check_search_args(**kwargs) -> None:
34+
"""Validate all search arguments."""
3435
check_search_mandatory_args(**kwargs)
3536
check_search_pagination_args(**kwargs)
3637

3738

3839
def check_search_mandatory_args(**kwargs) -> None:
40+
"""Validate that at least one mandatory search argument is provided."""
3941
mandatory_args = [
4042
kwargs.get("keywords"),
4143
kwargs.get("actor"),
@@ -77,6 +79,7 @@ def check_variations_args(**kwargs) -> None:
7779

7880

7981
def check_browse_nodes_args(**kwargs) -> None:
82+
"""Validate browse node arguments."""
8083
if not isinstance(kwargs.get("browse_node_ids"), List):
8184
error_message = "Argument browse_node_ids should be a List of strings."
8285
raise InvalidArgument(error_message)

amazon_paapi/helpers/requests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929

3030
def get_items_request(amazon_api, asin_chunk: List[str], **kwargs) -> GetItemsRequest:
31+
"""Create a GetItemsRequest for the Amazon API."""
3132
try:
3233
return GetItemsRequest(
3334
resources=_get_request_resources(GetItemsResource),
@@ -43,6 +44,7 @@ def get_items_request(amazon_api, asin_chunk: List[str], **kwargs) -> GetItemsRe
4344

4445

4546
def get_items_response(amazon_api, request: GetItemsRequest) -> List[Item]:
47+
"""Execute a GetItemsRequest and return the list of items."""
4648
try:
4749
response = amazon_api.api.get_items(request)
4850
except ApiException as exc:
@@ -56,6 +58,7 @@ def get_items_response(amazon_api, request: GetItemsRequest) -> List[Item]:
5658

5759

5860
def get_search_items_request(amazon_api, **kwargs) -> SearchItemsRequest:
61+
"""Create a SearchItemsRequest for the Amazon API."""
5962
try:
6063
return SearchItemsRequest(
6164
resources=_get_request_resources(SearchItemsResource),
@@ -70,6 +73,7 @@ def get_search_items_request(amazon_api, **kwargs) -> SearchItemsRequest:
7073

7174

7275
def get_search_items_response(amazon_api, request: SearchItemsRequest) -> SearchResult:
76+
"""Execute a SearchItemsRequest and return the search result."""
7377
try:
7478
response = amazon_api.api.search_items(request)
7579
except ApiException as exc:
@@ -83,6 +87,7 @@ def get_search_items_response(amazon_api, request: SearchItemsRequest) -> Search
8387

8488

8589
def get_variations_request(amazon_api, **kwargs) -> GetVariationsRequest:
90+
"""Create a GetVariationsRequest for the Amazon API."""
8691
try:
8792
return GetVariationsRequest(
8893
resources=_get_request_resources(GetVariationsResource),
@@ -99,6 +104,7 @@ def get_variations_request(amazon_api, **kwargs) -> GetVariationsRequest:
99104
def get_variations_response(
100105
amazon_api, request: GetVariationsRequest
101106
) -> VariationsResult:
107+
"""Execute a GetVariationsRequest and return the variations result."""
102108
try:
103109
response = amazon_api.api.get_variations(request)
104110
except ApiException as exc:
@@ -112,6 +118,7 @@ def get_variations_response(
112118

113119

114120
def get_browse_nodes_request(amazon_api, **kwargs) -> GetBrowseNodesRequest:
121+
"""Create a GetBrowseNodesRequest for the Amazon API."""
115122
try:
116123
return GetBrowseNodesRequest(
117124
resources=_get_request_resources(GetBrowseNodesResource),
@@ -128,6 +135,7 @@ def get_browse_nodes_request(amazon_api, **kwargs) -> GetBrowseNodesRequest:
128135
def get_browse_nodes_response(
129136
amazon_api, request: GetBrowseNodesRequest
130137
) -> List[BrowseNode]:
138+
"""Execute a GetBrowseNodesRequest and return the list of browse nodes."""
131139
try:
132140
response = amazon_api.api.get_browse_nodes(request)
133141
except ApiException as exc:
@@ -141,11 +149,13 @@ def get_browse_nodes_response(
141149

142150

143151
def _get_request_resources(resources) -> List[str]:
152+
"""Extract all resource strings from a resource class."""
144153
resources = inspect.getmembers(resources, lambda a: not inspect.isroutine(a))
145154
return [x[-1] for x in resources if isinstance(x[-1], str) and x[0][0:2] != "__"]
146155

147156

148157
def _manage_response_exceptions(error) -> NoReturn:
158+
"""Handle API exceptions and raise appropriate custom exceptions."""
149159
error_status = getattr(error, "status", None)
150160
error_body = getattr(error, "body", "") or ""
151161

amazon_paapi/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Models for the Amazon Product Advertising API responses."""
2+
13
from amazon_paapi.sdk.models import Availability, Condition, Merchant, SortBy
24

35
from .browse_nodes_result import BrowseNode

amazon_paapi/models/browse_nodes_result.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1+
"""Browse node result models for Amazon Product Advertising API."""
2+
13
from typing import List
24

35
from amazon_paapi.sdk import models as sdk_models
46

57

68
class BrowseNodeChild(sdk_models.BrowseNodeChild):
9+
"""Represent a child browse node."""
10+
711
context_free_name: str
812
display_name: str
913
id: str
1014

1115

1216
class BrowseNodeAncestor(BrowseNodeChild, sdk_models.BrowseNodeAncestor):
17+
"""Represent an ancestor browse node."""
18+
1319
ancestor: BrowseNodeChild
1420

1521

1622
class BrowseNode(sdk_models.BrowseNode):
23+
"""Represent a browse node with its hierarchy information."""
24+
1725
display_name: str
1826
id: str
1927
is_root: bool

0 commit comments

Comments
 (0)