Skip to content

Commit a08d122

Browse files
committed
fix last ruff errors
1 parent 16e1779 commit a08d122

7 files changed

Lines changed: 35 additions & 21 deletions

File tree

.pre-commit-config.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ repos:
1919
- id: name-tests-test
2020

2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: v0.6.9
22+
rev: v0.14.11
2323
hooks:
24-
- id: ruff
25-
args: [--fix, --exit-non-zero-on-fix]
2624
- id: ruff-format
25+
- id: ruff-check
26+
args: [--fix, --exit-non-zero-on-fix]
2727

2828
- repo: https://github.com/lk16/detect-missing-init
2929
rev: v0.1.6
@@ -32,18 +32,18 @@ repos:
3232
args: ["--create", "--python-folders", "amazon_paapi"]
3333

3434
- repo: https://github.com/pre-commit/mirrors-mypy
35-
rev: 'v1.11.2'
35+
rev: 'v1.19.1'
3636
hooks:
3737
- id: mypy
3838
exclude: sdk/
3939

4040
- repo: local
4141
hooks:
42-
- id: mypy
43-
name: Checking types with mypy
44-
language: system
45-
entry: "python -m mypy amazon_paapi"
46-
pass_filenames: false
42+
# - id: mypy
43+
# name: Checking types with mypy
44+
# language: system
45+
# entry: "python -m mypy amazon_paapi"
46+
# pass_filenames: false
4747

4848
- id: test
4949
name: Running tests

amazon_paapi/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Amazon Product Advertising API wrapper for Python."""
22

33
__author__ = "Sergio Abad"
4+
__all__ = ["AmazonApi", "get_asin"]
45

56
from .api import AmazonApi
67
from .tools import get_asin

amazon_paapi/api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def __init__(
4343
tag: str,
4444
country: CountryCode,
4545
throttling: float = 1,
46-
**kwargs: Any,
4746
) -> None:
4847
"""Initialize the Amazon API client with the provided credentials."""
4948
self._key = key

amazon_paapi/helpers/arguments.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from amazon_paapi.errors import InvalidArgument
88
from amazon_paapi.tools import get_asin
99

10+
MAX_PAGINATION_VALUE = 10
11+
1012

1113
def get_items_ids(items: str | list[str]) -> list[str]:
1214
"""Parse and extract ASINs from items input.
@@ -64,7 +66,9 @@ def check_search_pagination_args(**kwargs: Any) -> None:
6466
pagination_args = [kwargs.get("item_count"), kwargs.get("item_page")]
6567

6668
for arg in pagination_args:
67-
if arg is not None and (not isinstance(arg, int) or not 1 <= arg <= 10):
69+
if arg is not None and (
70+
not isinstance(arg, int) or not 1 <= arg <= MAX_PAGINATION_VALUE
71+
):
6872
raise InvalidArgument(error_message)
6973

7074

@@ -76,7 +80,9 @@ def check_variations_args(**kwargs: Any) -> None:
7680
variation_args = [kwargs.get("variation_count"), kwargs.get("variation_page")]
7781

7882
for arg in variation_args:
79-
if arg is not None and (not isinstance(arg, int) or not 1 <= arg <= 10):
83+
if arg is not None and (
84+
not isinstance(arg, int) or not 1 <= arg <= MAX_PAGINATION_VALUE
85+
):
8086
raise InvalidArgument(error_message)
8187

8288

amazon_paapi/helpers/requests.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
RequestError,
1414
TooManyRequests,
1515
)
16-
from amazon_paapi.models.browse_nodes_result import BrowseNode
17-
from amazon_paapi.models.item_result import Item
18-
from amazon_paapi.models.search_result import SearchResult
19-
from amazon_paapi.models.variations_result import VariationsResult
2016
from amazon_paapi.sdk.models.get_browse_nodes_request import GetBrowseNodesRequest
2117
from amazon_paapi.sdk.models.get_browse_nodes_resource import GetBrowseNodesResource
2218
from amazon_paapi.sdk.models.get_items_request import GetItemsRequest
@@ -29,8 +25,14 @@
2925
from amazon_paapi.sdk.rest import ApiException
3026
from amazon_paapi.sdk.rest import ApiException as ApiExceptionType
3127

28+
HTTP_TOO_MANY_REQUESTS = 429
29+
3230
if TYPE_CHECKING:
3331
from amazon_paapi.api import AmazonApi
32+
from amazon_paapi.models.browse_nodes_result import BrowseNode
33+
from amazon_paapi.models.item_result import Item
34+
from amazon_paapi.models.search_result import SearchResult
35+
from amazon_paapi.models.variations_result import VariationsResult
3436

3537

3638
def get_items_request(
@@ -64,7 +66,7 @@ def get_items_response(amazon_api: AmazonApi, request: GetItemsRequest) -> list[
6466
msg = "No items have been found"
6567
raise ItemsNotFound(msg)
6668

67-
return cast(List[Item], response.items_result.items)
69+
return cast("List[Item]", response.items_result.items)
6870

6971

7072
def get_search_items_request(
@@ -98,7 +100,7 @@ def get_search_items_response(
98100
msg = "No items have been found"
99101
raise ItemsNotFound(msg)
100102

101-
return cast(SearchResult, response.search_result)
103+
return cast("SearchResult", response.search_result)
102104

103105

104106
def get_variations_request(
@@ -132,7 +134,7 @@ def get_variations_response(
132134
msg = "No variation items have been found"
133135
raise ItemsNotFound(msg)
134136

135-
return cast(VariationsResult, response.variations_result)
137+
return cast("VariationsResult", response.variations_result)
136138

137139

138140
def get_browse_nodes_request(
@@ -166,7 +168,7 @@ def get_browse_nodes_response(
166168
msg = "No browse nodes have been found"
167169
raise ItemsNotFound(msg)
168170

169-
return cast(List[BrowseNode], response.browse_nodes_result.browse_nodes)
171+
return cast("List[BrowseNode]", response.browse_nodes_result.browse_nodes)
170172

171173

172174
def _get_request_resources(resource_class: type[object]) -> list[str]:
@@ -180,7 +182,7 @@ def _manage_response_exceptions(error: ApiExceptionType) -> NoReturn:
180182
error_status = getattr(error, "status", None)
181183
error_body = getattr(error, "body", "") or ""
182184

183-
if error_status == 429:
185+
if error_status == HTTP_TOO_MANY_REQUESTS:
184186
msg = (
185187
"Requests limit reached, try increasing throttling or wait before"
186188
" trying again"

amazon_paapi/tools/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
"""Tools for extracting information from Amazon URLs and ASINs."""
22

3+
__all__ = ["get_asin"]
4+
35
from .asin import get_asin

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ ignore = [
1414
"D213",
1515
"COM812",
1616
"ISC001",
17+
"FBT001",
18+
"FBT002",
19+
"N818", # TODO: Exception name should be named with an Error suffix
1720
]
1821
exclude = ["amazon_paapi/sdk/*", "docs/*"]
1922

@@ -30,6 +33,7 @@ exclude = ["amazon_paapi/sdk/*", "docs/*"]
3033
"PT027",
3134
"SLF001",
3235
]
36+
"api.py" = ["PLR0913"]
3337

3438
[tool.ruff.format]
3539
exclude = ["amazon_paapi/sdk/*", "docs/*", ".github"]

0 commit comments

Comments
 (0)