Skip to content

Commit 6ffd5da

Browse files
committed
fix remaining lint and type problems
1 parent 085de71 commit 6ffd5da

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

qbreader/_api_utils.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
import warnings
66
from enum import Enum, EnumType
7-
from typing import Iterable, Optional, Union, Tuple
7+
from typing import Iterable, Optional, Tuple, Union
88

99
from qbreader.types import (
10-
Difficulty,
10+
AlternateSubcategory,
1111
Category,
12+
Difficulty,
1213
Subcategory,
13-
AlternateSubcategory,
14+
UnnormalizedAlternateSubcategory,
1415
UnnormalizedCategory,
1516
UnnormalizedDifficulty,
1617
UnnormalizedSubcategory,
17-
UnnormalizedAlternateSubcategory,
1818
)
1919

2020

@@ -107,6 +107,7 @@ def normalize_subcat(unnormalized_subcats: UnnormalizedCategory):
107107
def category_correspondence(
108108
typed_alt_subcat: AlternateSubcategory,
109109
) -> Tuple[Category | None, Subcategory | None]:
110+
"""Return the corresponding category/subcategory for a alternate_subcategory."""
110111
if typed_alt_subcat in [
111112
AlternateSubcategory.ASTRONOMY,
112113
AlternateSubcategory.COMPUTER_SCIENCE,
@@ -146,7 +147,7 @@ def category_correspondence(
146147
AlternateSubcategory.MISC_LITERATURE,
147148
]:
148149
return (Category.LITERATURE, None)
149-
150+
150151
# Accounts for AlternateSubcategory.PRACTICES and AlternateSubcategory.BELIEFS
151152
return (None, None)
152153

@@ -156,12 +157,10 @@ def normalize_cats(
156157
unnormalized_subcats: UnnormalizedSubcategory,
157158
unnormalized_alt_subcats: UnnormalizedAlternateSubcategory,
158159
) -> Tuple[str, str, str]:
159-
"""
160-
Normalize a single or list of categories, subcategories, and alternate_subcategories
161-
to their corresponding comma-separated strings, taking into account categories and
162-
subcategories that must be added for the alternate_subcategories to work.
163-
"""
164-
160+
"""Normalize a single or list of categories, subcategories, and\
161+
alternate_subcategories to their corresponding comma-separated strings, taking into\
162+
account categories and subcategories that must be added for the\
163+
alternate_subcategories to work."""
165164
typed_alt_subcats: list[AlternateSubcategory] = []
166165

167166
if isinstance(unnormalized_alt_subcats, str):
@@ -186,8 +185,8 @@ def normalize_cats(
186185
elif isinstance(unnormalized_cats, str):
187186
final_cats = [Category(unnormalized_cats), *to_be_pushed_cats]
188187
elif isinstance(unnormalized_cats, Iterable):
189-
for cat in unnormalized_cats:
190-
final_cats.append(Category(cat))
188+
for unnormalized_cat in unnormalized_cats:
189+
final_cats.append(Category(unnormalized_cat))
191190
final_cats.append(*to_be_pushed_cats)
192191

193192
final_subcats = []
@@ -196,8 +195,8 @@ def normalize_cats(
196195
elif isinstance(unnormalized_subcats, str):
197196
final_subcats = [Subcategory(unnormalized_subcats), *to_be_pushed_subcats]
198197
elif isinstance(unnormalized_subcats, Iterable):
199-
for subcat in unnormalized_subcats:
200-
final_subcats.append(Subcategory(subcat))
198+
for unnormalized_subcat in unnormalized_subcats:
199+
final_subcats.append(Subcategory(unnormalized_subcat))
201200
final_subcats.append(*to_be_pushed_subcats)
202201

203202
return (

qbreader/asynchronous.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
QuestionType,
1717
SearchType,
1818
Tossup,
19+
UnnormalizedAlternateSubcategory,
1920
UnnormalizedCategory,
2021
UnnormalizedDifficulty,
2122
UnnormalizedSubcategory,
22-
UnnormalizedAlternateSubcategory,
2323
Year,
2424
)
2525

@@ -116,7 +116,8 @@ class type.
116116
The subcategories to search for. Can be a single or an array of
117117
`Subcategory` enums or strings. The API does not check for consistency
118118
between categories and subcategories.
119-
alternate_subcategories : qbreader.types.UnnormalizedAlternateSubcategory, optional
119+
alternate_subcategories : qbreader.types.UnnormalizedAlternateSubcategory,\
120+
optional
120121
The alternate subcategories to search for. Can be a single or an array of
121122
`AlternateSubcategory` enums or strings. The API does not check for
122123
consistency between categories and subcategories
@@ -244,7 +245,8 @@ async def random_tossup(
244245
The subcategories to search for. Can be a single or an array of
245246
`Subcategory` enums or strings. The API does not check for consistency
246247
between categories and subcategories.
247-
alternate_subcategories : qbreader.types.UnnormalizedAlternateSubcategory, optional
248+
alternate_subcategories : qbreader.types.UnnormalizedAlternateSubcategory,\
249+
optional
248250
The alternate subcategories to search for. Can be a single or an array of
249251
`AlternateSubcategory` enums or strings. The API does not check for
250252
consistency between categories and subcategories
@@ -327,10 +329,11 @@ async def random_bonus(
327329
The subcategories to search for. Can be a single or an array of
328330
`Subcategory` enums or strings. The API does not check for consistency
329331
between categories and subcategories.
330-
alternate_subcategories: qbreaader.types.UnnormalizedAlternateSubcategory, optional
332+
alternate_subcategories: qbreader.types.UnnormalizedAlternateSubcategory, \
333+
optional
331334
The alternates subcategories to search for. Can be a single or an array of
332-
`AlternateSubcategory` enum variants or strings. The API does not check for consistency
333-
between categories, subcategories, and alternate subcategories.
335+
`AlternateSubcategory` enum variants or strings. The API does not check for
336+
consistency between categories, subcategories, and alternate subcategories.
334337
number : int, default = 1
335338
The number of bonuses to return.
336339
min_year : int, default = Year.MIN_YEAR

qbreader/synchronous.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
QuestionType,
1717
SearchType,
1818
Tossup,
19-
UnnormalizedDifficulty,
19+
UnnormalizedAlternateSubcategory,
2020
UnnormalizedCategory,
21+
UnnormalizedDifficulty,
2122
UnnormalizedSubcategory,
22-
UnnormalizedAlternateSubcategory,
2323
Year,
2424
)
2525

@@ -81,10 +81,11 @@ class type.
8181
The subcategories to search for. Can be a single or an array of
8282
`Subcategory` enums or strings. The API does not check for consistency
8383
between categories and subcategories.
84-
alternate_subcategories: qbreaader.types.UnnormalizedAlternateSubcategory, optional
84+
alternate_subcategories: qbreaader.types.UnnormalizedAlternateSubcategory,\
85+
optional
8586
The alternates subcategories to search for. Can be a single or an array of
86-
`AlternateSubcategory` enum variants or strings. The API does not check for consistency
87-
between categories, subcategories, and alternate subcategories.
87+
`AlternateSubcategory` enum variants or strings. The API does not check for
88+
consistency between categories, subcategories, and alternate subcategories.
8889
maxReturnLength : int, default = 25
8990
The maximum number of questions to return.
9091
tossupPagination : int, default = 1
@@ -209,10 +210,11 @@ def random_tossup(
209210
The subcategories to search for. Can be a single or an array of
210211
`Subcategory` enums or strings. The API does not check for consistency
211212
between categories and subcategories.
212-
alternate_subcategories: qbreaader.types.UnnormalizedAlternateSubcategory, optional
213+
alternate_subcategories: qbreaader.types.UnnormalizedAlternateSubcategory,
214+
optional
213215
The alternates subcategories to search for. Can be a single or an array of
214-
`AlternateSubcategory` enum variants or strings. The API does not check for consistency
215-
between categories, subcategories, and alternate subcategories.
216+
`AlternateSubcategory` enum variants or strings. The API does not check for
217+
consistency between categories, subcategories, and alternate subcategories.
216218
number : int, default = 1
217219
The number of tossups to return.
218220
min_year : int, default = Year.MIN_YEAR

qbreader/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ def __str__(self) -> str:
688688
UnnormalizedAlternateSubcategory: TypeAlias = Optional[
689689
Union[AlternateSubcategory, str, Iterable[Union[AlternateSubcategory, str]]]
690690
]
691-
"""Type alias for unnormalized alternate subcategories. Union of `AlternateSubcategory`,
691+
"""Type alias for unnormalized alternate subcategories. Union of `AlternateSubcategory`,
692692
`str`, and `collections.abc.Iterable` containing either."""
693693

694694

0 commit comments

Comments
 (0)