Skip to content

Commit 2b28c68

Browse files
committed
ci: A few quality fixes
1 parent 085c6ca commit 2b28c68

3 files changed

Lines changed: 26 additions & 43 deletions

File tree

src/griffe_typedoc/decoder.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import json
66
import re
7+
from contextlib import suppress
78
from functools import wraps
89
from typing import Any, Callable
910

@@ -72,10 +73,8 @@ def wrapper(obj_dict: dict[str, Any], symbol_id_map: dict[int, Any]) -> Any:
7273
# Assign object as parent on children.
7374
if "children" in obj_dict:
7475
for child in obj.children:
75-
try:
76+
with suppress(AttributeError): # ints in groups
7677
child.parent = obj
77-
except AttributeError:
78-
pass # ints in groups
7978

8079
return obj
8180

@@ -505,7 +504,15 @@ def _load_group(obj_dict: dict) -> Group:
505504

506505

507506
class TypedocDecoder(json.JSONDecoder):
508-
def __init__(self, *args, **kwargs) -> None:
507+
"""JSON decoder."""
508+
509+
def __init__(self, *args: Any, **kwargs: Any) -> None:
510+
"""Initialize the decoder.
511+
512+
Parameters:
513+
*args: Arguments passed to parent init method.
514+
*kwargs: Keyword arguments passed to parent init method.
515+
"""
509516
kwargs["object_hook"] = self._object_hook
510517
super().__init__(*args, **kwargs)
511518
self._symbol_map: dict[int, Any] = {}
@@ -515,11 +522,6 @@ def _object_hook(self, obj_dict: dict[str, Any]) -> dict[str, Any] | str:
515522
516523
The [`json.loads`][] method walks the tree from bottom to top.
517524
518-
Examples:
519-
>>> import json
520-
>>> from griffe.encoders import json_decoder
521-
>>> json.loads(..., object_hook=json_decoder)
522-
523525
Parameters:
524526
obj_dict: The dictionary to decode.
525527
@@ -561,5 +563,3 @@ def _object_hook(self, obj_dict: dict[str, Any]) -> dict[str, Any] | str:
561563

562564
# Return dict as is.
563565
return obj_dict
564-
565-
__all__ = ["json_decoder"]

src/griffe_typedoc/loader.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
import re
66
import subprocess
77
from tempfile import NamedTemporaryFile
8+
from typing import TYPE_CHECKING
89

9-
from griffe_typedoc.dataclasses import Project
1010
from griffe_typedoc.decoder import TypedocDecoder
1111
from griffe_typedoc.logger import get_logger
1212

13+
if TYPE_CHECKING:
14+
from griffe_typedoc.dataclasses import Project
15+
1316
logger = get_logger(__name__)
1417

1518

@@ -18,6 +21,15 @@ def _double_brackets(message: str) -> str:
1821

1922

2023
def load(typedoc_command: str | list[str], working_directory: str = ".") -> Project:
24+
"""Load TypeScript API data using TypeDoc.
25+
26+
Parameters:
27+
typedoc_command: Name/path of the 1`typedoc` executable, or a command as list.
28+
working_directory: Where to execute the command.
29+
30+
Returns:
31+
Top-level project object containing API data.
32+
"""
2133
with NamedTemporaryFile("r+") as tmpfile:
2234
if isinstance(typedoc_command, str):
2335
typedoc_command += f" --json {tmpfile.name}"
@@ -27,7 +39,7 @@ def load(typedoc_command: str | list[str], working_directory: str = ".") -> Proj
2739
shell = False
2840
env = os.environ.copy()
2941
env["NO_COLOR"] = "1"
30-
process = subprocess.Popen(
42+
process = subprocess.Popen( # noqa: S603
3143
typedoc_command,
3244
shell=shell,
3345
text=True,

src/griffe_typedoc/logger.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,4 @@
1-
"""This module contains logging utilities.
2-
3-
We provide the [`patch_loggers`][griffe_typedoc.logger.patch_loggers]
4-
function so dependant libraries can patch loggers as they see fit.
5-
6-
For example, to fit in the MkDocs logging configuration
7-
and prefix each log message with the module name:
8-
9-
```python
10-
import logging
11-
from griffe.logger import patch_loggers
12-
13-
14-
class LoggerAdapter(logging.LoggerAdapter):
15-
def __init__(self, prefix, logger):
16-
super().__init__(logger, {})
17-
self.prefix = prefix
18-
19-
def process(self, msg, kwargs):
20-
return f"{self.prefix}: {msg}", kwargs
21-
22-
23-
def get_logger(name):
24-
logger = logging.getLogger(f"mkdocs.plugins.{name}")
25-
return LoggerAdapter(name, logger)
26-
27-
28-
patch_loggers(get_logger)
29-
```
30-
"""
1+
"""This module contains logging utilities."""
312

323
from __future__ import annotations
334

0 commit comments

Comments
 (0)