Skip to content

Commit bd89079

Browse files
committed
finicky autodoc nuances, fixed type aliases in signatures
1 parent 9a5f423 commit bd89079

6 files changed

Lines changed: 63 additions & 33 deletions

File tree

docs/conf.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,12 @@
3636

3737
autodoc_member_order = "bysource"
3838
autodoc_type_aliases = {
39-
"Async": "qbreader.asynchronous.Async",
40-
"Sync": "qbreader.synchronous.Sync",
41-
"Tossup": "qbreader.types.Tossup",
42-
"Bonus": "qbreader.types.Bonus",
43-
"Category": "qbreader.types.Category",
44-
"Subcategory": "qbreader.types.Subcategory",
45-
"Difficulty": "qbreader.types.Difficulty",
46-
"QueryResponse": "qbreader.types.QueryResponse",
47-
"Directive": "qbreader.types.Directive",
48-
"AnswerJudgement": "qbreader.types.AnswerJudgement",
49-
"Packet": "qbreader.types.Packet",
39+
"QuestionType": "qbreader.types.QuestionType",
40+
"SearchType": "qbreader.types.SearchType",
41+
"ValidDifficulties": "qbreader.types.ValidDifficulties",
42+
"UnnormalizedDifficulty": "qbreader.types.UnnormalizedDifficulty",
43+
"UnnormalizedCategory": "qbreader.types.UnnormalizedCategory",
44+
"UnnormalizedSubcategory": "qbreader.types.UnnormalizedSubcategory",
5045
}
5146

5247
# -- Options for HTML output -------------------------------------------------
@@ -58,5 +53,6 @@
5853
html_static_path = ["_static"]
5954

6055
intersphinx_mapping = {
61-
"py": ("https://docs.python.org/3", None),
56+
"python": ("https://docs.python.org/3", None),
57+
"aiohttp": ("https://docs.aiohttp.org/en/stable/", None),
6258
}

qbreader/__init__.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
1-
"""The official qbreader API python wrapper."""
1+
"""The official qbreader API python wrapper.
2+
3+
.. note::
4+
Even though useful type aliases defined in `qbreader.types` are reexported here,
5+
they are not documented here by `sphinx-autodoc`, but are documented in the
6+
`types` module.
7+
8+
See also:
9+
* https://github.com/sphinx-doc/sphinx/issues/8547
10+
* https://github.com/sphinx-doc/sphinx/issues/1063
11+
"""
212

313
import importlib.metadata
414

15+
import qbreader.types as types
516
from qbreader.asynchronous import Async
617
from qbreader.synchronous import Sync
7-
from qbreader.types import (
8-
AnswerJudgement,
9-
Bonus,
10-
Category,
11-
Difficulty,
12-
Directive,
13-
Packet,
14-
QueryResponse,
15-
Subcategory,
16-
Tossup,
17-
)
18+
from qbreader.types import *
1819

1920
__version__ = importlib.metadata.version("qbreader")
2021
__all__ = (
2122
"Async",
2223
"Sync",
23-
"Tossup",
24-
"Bonus",
25-
"Category",
26-
"Subcategory",
27-
"Difficulty",
28-
"QueryResponse",
29-
"Directive",
30-
"AnswerJudgement",
31-
"Packet",
24+
"types",
3225
)
3326

27+
# add all symbols from qbreader.types to __all__
28+
__all__ += types.__all__
29+
3430
del importlib

qbreader/_api_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Useful functions used by both the asynchronous and synchronous API wrappers."""
22

3+
from __future__ import annotations
4+
35
import warnings
46
from enum import Enum, EnumType
57
from typing import Iterable, Optional, Union

qbreader/asynchronous.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Directly access the qbreader API asynchronously."""
22

3+
from __future__ import annotations
4+
35
from typing import Optional, Self, Type
46

57
import aiohttp

qbreader/synchronous.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Directly access the qbreader API synchronously."""
22

3+
from __future__ import annotations
4+
35
from typing import Optional, Self
46

57
import requests

qbreader/types.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,10 @@ def __str__(self) -> str:
492492
QuestionType: TypeAlias = Union[
493493
Literal["tossup", "bonus", "all"], Type[Tossup], Type[Bonus]
494494
]
495+
"""Type alias for question types."""
496+
495497
SearchType: TypeAlias = Literal["question", "answer", "all"]
498+
"""Type alias for query search types."""
496499

497500
ValidDifficulties: TypeAlias = Literal[
498501
0,
@@ -518,12 +521,41 @@ def __str__(self) -> str:
518521
"9",
519522
"10",
520523
]
524+
"""Type alias for valid difficulties."""
525+
521526
UnnormalizedDifficulty: TypeAlias = Optional[
522527
Union[Difficulty, ValidDifficulties, Iterable[Union[Difficulty, ValidDifficulties]]]
523528
]
529+
"""Type alias for unnormalized difficulties. Union of `Difficulty`, `ValidDifficulties`,
530+
and `collections.abc.Iterable` containing either."""
531+
524532
UnnormalizedCategory: TypeAlias = Optional[
525533
Union[Category, str, Iterable[Union[Category, str]]]
526534
]
535+
"""Type alias for unnormalized categories. Union of `Category`, `str`, and
536+
`collections.abc.Iterable` containing either."""
537+
527538
UnnormalizedSubcategory: TypeAlias = Optional[
528539
Union[Subcategory, str, Iterable[Union[Subcategory, str]]]
529540
]
541+
"""Type alias for unnormalized subcategories. Union of `Subcategory`, `str`, and
542+
`collections.abc.Iterable` containing either."""
543+
544+
545+
__all__ = (
546+
"Tossup",
547+
"Bonus",
548+
"Packet",
549+
"QueryResponse",
550+
"AnswerJudgement",
551+
"Category",
552+
"Subcategory",
553+
"Difficulty",
554+
"Directive",
555+
"QuestionType",
556+
"SearchType",
557+
"ValidDifficulties",
558+
"UnnormalizedDifficulty",
559+
"UnnormalizedCategory",
560+
"UnnormalizedSubcategory",
561+
)

0 commit comments

Comments
 (0)