|
7 | 7 |
|
8 | 8 |
|
9 | 9 | def get_items_ids(items: Union[str, List[str]]) -> List[str]: |
10 | | - if not isinstance(items, str) and not isinstance(items, List): |
11 | | - msg = "Invalid items argument, it should be a string or List of strings" |
12 | | - raise InvalidArgument(msg) |
| 10 | + """Parse and extract ASINs from items input. |
13 | 11 |
|
| 12 | + Args: |
| 13 | + items: Either a comma-separated string of ASINs/URLs or a list of ASINs/URLs. |
| 14 | +
|
| 15 | + Returns: |
| 16 | + A list of extracted ASINs. |
| 17 | +
|
| 18 | + Raises: |
| 19 | + InvalidArgument: If items is not a string or list. |
| 20 | +
|
| 21 | + """ |
14 | 22 | if isinstance(items, str): |
15 | 23 | items_ids = items.split(",") |
16 | | - items_ids = [get_asin(x.strip()) for x in items_ids] |
| 24 | + return [get_asin(x.strip()) for x in items_ids] |
17 | 25 |
|
18 | | - else: |
19 | | - items_ids = [get_asin(x.strip()) for x in items] |
| 26 | + if isinstance(items, list): |
| 27 | + return [get_asin(x.strip()) for x in items] |
20 | 28 |
|
21 | | - return items_ids |
| 29 | + msg = "Invalid items argument, it should be a string or List of strings" # type: ignore[unreachable] |
| 30 | + raise InvalidArgument(msg) |
22 | 31 |
|
23 | 32 |
|
24 | 33 | def check_search_args(**kwargs) -> None: |
@@ -46,29 +55,25 @@ def check_search_mandatory_args(**kwargs) -> None: |
46 | 55 |
|
47 | 56 |
|
48 | 57 | def check_search_pagination_args(**kwargs) -> None: |
| 58 | + """Validate pagination arguments for search requests.""" |
49 | 59 | error_message = "Args item_count and item_page should be integers between 1 and 10." |
50 | 60 | pagination_args = [kwargs.get("item_count"), kwargs.get("item_page")] |
51 | | - pagination_args = [arg for arg in pagination_args if arg] |
52 | 61 |
|
53 | | - if not all(isinstance(arg, int) for arg in pagination_args): |
54 | | - raise InvalidArgument(error_message) |
55 | | - |
56 | | - if not all(1 <= arg <= 10 for arg in pagination_args): |
57 | | - raise InvalidArgument(error_message) |
| 62 | + for arg in pagination_args: |
| 63 | + if arg is not None and (not isinstance(arg, int) or not 1 <= arg <= 10): |
| 64 | + raise InvalidArgument(error_message) |
58 | 65 |
|
59 | 66 |
|
60 | 67 | def check_variations_args(**kwargs) -> None: |
| 68 | + """Validate variation arguments for get_variations requests.""" |
61 | 69 | error_message = ( |
62 | 70 | "Args variation_count and variation_page should be integers between 1 and 10." |
63 | 71 | ) |
64 | 72 | variation_args = [kwargs.get("variation_count"), kwargs.get("variation_page")] |
65 | | - variation_args = [arg for arg in variation_args if arg] |
66 | | - |
67 | | - if not all(isinstance(arg, int) for arg in variation_args): |
68 | | - raise InvalidArgument(error_message) |
69 | 73 |
|
70 | | - if not all(1 <= arg <= 10 for arg in variation_args): |
71 | | - raise InvalidArgument(error_message) |
| 74 | + for arg in variation_args: |
| 75 | + if arg is not None and (not isinstance(arg, int) or not 1 <= arg <= 10): |
| 76 | + raise InvalidArgument(error_message) |
72 | 77 |
|
73 | 78 |
|
74 | 79 | def check_browse_nodes_args(**kwargs) -> None: |
|
0 commit comments