Skip to content

Commit 83d26a9

Browse files
authored
Merge pull request #114 from sergioteula/fix-pylint-errors
Fix pylint errors
2 parents a907ce4 + fc22937 commit 83d26a9

File tree

15 files changed

+106
-92
lines changed

15 files changed

+106
-92
lines changed

.githooks/pre-push

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ source "${ROOT_DIR}/scripts/helpers"
66
./scripts/check_isort
77
./scripts/check_black
88
./scripts/check_flake8
9+
./scripts/check_pylint
910

1011
header "Proceeding with push"

.github/workflows/lint-and-test.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,15 @@ jobs:
4040
uses: actions/checkout@v2
4141
- name: Check code errors
4242
run: ./scripts/check_flake8
43+
44+
pylint:
45+
runs-on: ubuntu-latest
46+
container:
47+
image: sergioteula/pytools
48+
volumes:
49+
- ${{github.workspace}}:/code
50+
steps:
51+
- name: Check out code
52+
uses: actions/checkout@v2
53+
- name: Check code errors
54+
run: ./scripts/check_pylint

amazon_paapi/api.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ def __init__(
4040
):
4141
self._key = key
4242
self._secret = secret
43-
self._tag = tag
44-
self._country = country
45-
self._throttling = float(throttling)
4643
self._last_query_time = time.time() - throttling
44+
self.tag = tag
45+
self.country = country
46+
self.throttling = float(throttling)
4747

4848
try:
4949
self._host = "webservices.amazon." + models.regions.DOMAINS[country]
50-
self._region = models.regions.REGIONS[country]
51-
self._marketplace = "www.amazon." + models.regions.DOMAINS[country]
50+
self.region = models.regions.REGIONS[country]
51+
self.marketplace = "www.amazon." + models.regions.DOMAINS[country]
5252
except KeyError as error:
5353
raise InvalidArgumentException("Country code is not correct") from error
5454

55-
self._api = DefaultApi(key, secret, self._host, self._region)
55+
self.api = DefaultApi(key, secret, self._host, self.region)
5656

5757
def get_items(
5858
self,
@@ -329,7 +329,7 @@ def get_browse_nodes(
329329
return requests.get_browse_nodes_response(self, request)
330330

331331
def _throttle(self):
332-
wait_time = self._throttling - (time.time() - self._last_query_time)
332+
wait_time = self.throttling - (time.time() - self._last_query_time)
333333
if wait_time > 0:
334334
time.sleep(wait_time)
335335
self._last_query_time = time.time()

amazon_paapi/errors/exceptions.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,36 @@ def __init__(self, reason: str):
99
self.reason = reason
1010

1111
def __str__(self) -> str:
12-
return "%s" % self.reason
12+
return self.reason
1313

1414

1515
class InvalidArgumentException(AmazonException):
1616
"""Raised when arguments are not correct."""
1717

18-
pass
19-
2018

2119
class AsinNotFoundException(AmazonException):
2220
"""Raised if the ASIN for an item is not found."""
2321

24-
pass
25-
2622

2723
class ApiRequestException(AmazonException):
2824
"""Raised if the request to Amazon API fails"""
2925

30-
pass
31-
3226

3327
class MalformedRequestException(AmazonException):
3428
"""Raised if the request for Amazon API is not correctly formed"""
3529

36-
pass
37-
3830

3931
class ItemsNotFoundException(AmazonException):
4032
"""Raised if no items are found"""
4133

42-
pass
43-
4434

4535
class TooManyRequestsException(AmazonException):
4636
"""Raised when requests limit is reached"""
4737

48-
pass
49-
5038

5139
class InvalidPartnerTagException(AmazonException):
5240
"""Raised if the partner tag is not present or invalid"""
5341

54-
pass
55-
5642

5743
class AssociateValidationException(AmazonException):
5844
"""Raised when credentials are not valid for the selected country"""
59-
60-
pass

amazon_paapi/helpers/requests.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ def get_items_request(amazon_api, asin_chunk: List[str], **kwargs) -> GetItemsRe
3333
return GetItemsRequest(
3434
resources=_get_request_resources(GetItemsResource),
3535
partner_type=PartnerType.ASSOCIATES,
36-
marketplace=amazon_api._marketplace,
37-
partner_tag=amazon_api._tag,
36+
marketplace=amazon_api.marketplace,
37+
partner_tag=amazon_api.tag,
3838
item_ids=asin_chunk,
39-
**kwargs
39+
**kwargs,
4040
)
41-
except TypeError as e:
41+
except TypeError as exc:
4242
raise MalformedRequestException(
43-
"Parameters for get_items request are not correct: " + str(e)
44-
)
43+
f"Parameters for get_items request are not correct: {exc}"
44+
) from exc
4545

4646

4747
def get_items_response(amazon_api, request: GetItemsRequest) -> List[Item]:
4848
try:
49-
response = amazon_api._api.get_items(request)
50-
except ApiException as e:
51-
_manage_response_exceptions(e)
49+
response = amazon_api.api.get_items(request)
50+
except ApiException as exc:
51+
_manage_response_exceptions(exc)
5252

5353
if response.items_result is None:
5454
raise ItemsNotFoundException("No items have been found")
@@ -61,21 +61,21 @@ def get_search_items_request(amazon_api, **kwargs) -> SearchItemsRequest:
6161
return SearchItemsRequest(
6262
resources=_get_request_resources(SearchItemsResource),
6363
partner_type=PartnerType.ASSOCIATES,
64-
marketplace=amazon_api._marketplace,
65-
partner_tag=amazon_api._tag,
66-
**kwargs
64+
marketplace=amazon_api.marketplace,
65+
partner_tag=amazon_api.tag,
66+
**kwargs,
6767
)
68-
except TypeError as e:
68+
except TypeError as exc:
6969
raise MalformedRequestException(
70-
"Parameters for search_items request are not correct: " + str(e)
71-
)
70+
f"Parameters for search_items request are not correct: {exc}"
71+
) from exc
7272

7373

7474
def get_search_items_response(amazon_api, request: SearchItemsRequest) -> SearchResult:
7575
try:
76-
response = amazon_api._api.search_items(request)
77-
except ApiException as e:
78-
_manage_response_exceptions(e)
76+
response = amazon_api.api.search_items(request)
77+
except ApiException as exc:
78+
_manage_response_exceptions(exc)
7979

8080
if response.search_result is None:
8181
raise ItemsNotFoundException("No items have been found")
@@ -88,23 +88,23 @@ def get_variations_request(amazon_api, **kwargs) -> GetVariationsRequest:
8888
return GetVariationsRequest(
8989
resources=_get_request_resources(GetVariationsResource),
9090
partner_type=PartnerType.ASSOCIATES,
91-
marketplace=amazon_api._marketplace,
92-
partner_tag=amazon_api._tag,
93-
**kwargs
91+
marketplace=amazon_api.marketplace,
92+
partner_tag=amazon_api.tag,
93+
**kwargs,
9494
)
95-
except TypeError as e:
95+
except TypeError as exc:
9696
raise MalformedRequestException(
97-
"Parameters for get_variations request are not correct: " + str(e)
98-
)
97+
f"Parameters for get_variations request are not correct: {exc}"
98+
) from exc
9999

100100

101101
def get_variations_response(
102102
amazon_api, request: GetVariationsRequest
103103
) -> VariationsResult:
104104
try:
105-
response = amazon_api._api.get_variations(request)
106-
except ApiException as e:
107-
_manage_response_exceptions(e)
105+
response = amazon_api.api.get_variations(request)
106+
except ApiException as exc:
107+
_manage_response_exceptions(exc)
108108

109109
if response.variations_result is None:
110110
raise ItemsNotFoundException("No variation items have been found")
@@ -117,23 +117,23 @@ def get_browse_nodes_request(amazon_api, **kwargs) -> GetBrowseNodesRequest:
117117
return GetBrowseNodesRequest(
118118
resources=_get_request_resources(GetBrowseNodesResource),
119119
partner_type=PartnerType.ASSOCIATES,
120-
marketplace=amazon_api._marketplace,
121-
partner_tag=amazon_api._tag,
122-
**kwargs
120+
marketplace=amazon_api.marketplace,
121+
partner_tag=amazon_api.tag,
122+
**kwargs,
123123
)
124-
except TypeError as e:
124+
except TypeError as exc:
125125
raise MalformedRequestException(
126-
"Parameters for get_browse_nodes request are not correct: " + str(e)
127-
)
126+
f"Parameters for get_browse_nodes request are not correct: {exc}"
127+
) from exc
128128

129129

130130
def get_browse_nodes_response(
131131
amazon_api, request: GetBrowseNodesRequest
132132
) -> List[BrowseNode]:
133133
try:
134-
response = amazon_api._api.get_browse_nodes(request)
135-
except ApiException as e:
136-
_manage_response_exceptions(e)
134+
response = amazon_api.api.get_browse_nodes(request)
135+
except ApiException as exc:
136+
_manage_response_exceptions(exc)
137137

138138
if response.browse_nodes_result is None:
139139
raise ItemsNotFoundException("No browse nodes have been found")
@@ -142,7 +142,7 @@ def get_browse_nodes_response(
142142

143143

144144
def _get_request_resources(resources) -> List[str]:
145-
resources = inspect.getmembers(resources, lambda a: not (inspect.isroutine(a)))
145+
resources = inspect.getmembers(resources, lambda a: not inspect.isroutine(a))
146146
resources = [
147147
x[-1] for x in resources if isinstance(x[-1], str) and x[0][0:2] != "__"
148148
]
@@ -157,16 +157,16 @@ def _manage_response_exceptions(error) -> None:
157157
" trying again"
158158
)
159159

160-
elif "InvalidParameterValue" in error.body:
160+
if "InvalidParameterValue" in error.body:
161161
raise InvalidArgumentException(
162162
"The value provided in the request for atleast one parameter is"
163163
" invalid."
164164
)
165165

166-
elif "InvalidPartnerTag" in error.body:
166+
if "InvalidPartnerTag" in error.body:
167167
raise InvalidArgumentException("The partner tag is invalid or not present.")
168168

169-
elif "InvalidAssociate" in error.body:
169+
if "InvalidAssociate" in error.body:
170170
raise AssociateValidationException(
171171
"Used credentials are not valid for the selected country."
172172
)

amazon_paapi/models/item_result.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from ..sdk import models
44

5-
"""Shared models"""
6-
75

86
class ApiLabelLocale:
97
label: str
@@ -55,9 +53,6 @@ class ApiPrice:
5553
price_type_label: str
5654

5755

58-
"""Image models"""
59-
60-
6156
class ApiImageSize(models.ImageSize):
6257
url: str
6358
height: str
@@ -75,9 +70,6 @@ class ApiImages(models.Images):
7570
variants: List[ApiImageType]
7671

7772

78-
"""Item info models"""
79-
80-
8173
class ApiByLineInfo(models.ByLineInfo):
8274
brand: ApiSingleStringValuedAttribute
8375
contributors: ApiSingleStringValuedAttribute
@@ -161,9 +153,6 @@ class ApiItemInfo(models.ItemInfo):
161153
trade_in_info: ApiTradeInInfo
162154

163155

164-
"""Offers model"""
165-
166-
167156
class ApiOfferAvailability(models.OfferAvailability):
168157
max_order_quantity: int
169158
message: str
@@ -247,9 +236,6 @@ class ApiOffers(models.Offers):
247236
listings: List[ApiListings]
248237

249238

250-
"""Browse node info model"""
251-
252-
253239
class ApiBrowseNode(models.BrowseNode):
254240
ancestor: str
255241
context_free_name: str
@@ -270,9 +256,6 @@ class ApiBrowseNodeInfo(models.BrowseNodeInfo):
270256
website_sales_rank: ApiWebsiteSalesRank
271257

272258

273-
"""Main model"""
274-
275-
276259
class Item(models.Item):
277260
asin: str
278261
browse_node_info: ApiBrowseNodeInfo

amazon_paapi/models/regions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Country(object):
1+
class Country:
22
AU = "AU"
33
BR = "BR"
44
CA = "CA"
@@ -20,7 +20,6 @@ class Country(object):
2020
US = "US"
2121

2222

23-
"""Available regions for the Amazon API."""
2423
REGIONS = {
2524
"AU": "us-west-2",
2625
"BR": "us-east-1",
@@ -43,7 +42,7 @@ class Country(object):
4342
"US": "us-east-1",
4443
}
4544

46-
"""Domains for each region on the Amazon API."""
45+
4746
DOMAINS = {
4847
"AU": "com.au",
4948
"BR": "com.br",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import List
22

3-
from ..sdk.models import SearchResult
3+
from ..sdk import models as sdk_models
44
from .item_result import Item
55

66

7-
class SearchResult(SearchResult):
7+
class SearchResult(sdk_models.SearchResult):
88
items: List[Item]
99
total_result_count: int
1010
search_url: str

amazon_paapi/models/variations_result.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import List
22

3-
from ..sdk.models import VariationsResult, VariationSummary
3+
from ..sdk import models as sdk_models
44
from .item_result import Item
55

66

@@ -21,13 +21,13 @@ class ApiVariationPrice:
2121
lowest_price: ApiPrice
2222

2323

24-
class ApiVariationSummary(VariationSummary):
24+
class ApiVariationSummary(sdk_models.VariationSummary):
2525
page_count: int
2626
price: ApiVariationPrice
2727
variation_count: int
2828
variation_dimensions: List[ApiVariationDimension]
2929

3030

31-
class VariationsResult(VariationsResult):
31+
class VariationsResult(sdk_models.VariationsResult):
3232
items: List[Item]
3333
variation_summary: ApiVariationSummary

examples/example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from amazon_paapi import AmazonApi
44

5+
# pylint: disable=no-member
56
amazon = AmazonApi(
67
secrets.KEY, secrets.SECRET, secrets.TAG, secrets.COUNTRY, throttling=2
78
)

0 commit comments

Comments
 (0)