Skip to content

Commit 0822232

Browse files
pre-commit-ci[bot]fajpunk
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 1369b61 commit 0822232

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

src/sphinx_autodoc_typehints/__init__.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,12 @@ def _get_formatted_annotation(annotation: TypeVar) -> TypeVar:
407407
elif what == "method":
408408
# bail if it is a local method as we cannot determine if first argument needs to be deleted or not
409409
if "<locals>" in obj.__qualname__ and not _is_dataclass(name, what, obj.__qualname__):
410-
_LOGGER.warning('Cannot handle as a local function: "%s" (use @functools.wraps)', name, type='sphinx_autodoc_typehints', subtype='local_function')
410+
_LOGGER.warning(
411+
'Cannot handle as a local function: "%s" (use @functools.wraps)',
412+
name,
413+
type="sphinx_autodoc_typehints",
414+
subtype="local_function",
415+
)
411416
return None
412417
outer = inspect.getmodule(obj)
413418
for class_name in obj.__qualname__.split(".")[:-1]:
@@ -500,7 +505,9 @@ def _execute_guarded_code(autodoc_mock_imports: list[str], obj: Any, module_code
500505
with mock(autodoc_mock_imports):
501506
exec(guarded_code, getattr(obj, "__globals__", obj.__dict__)) # noqa: S102
502507
except Exception as exc: # noqa: BLE001
503-
_LOGGER.warning("Failed guarded type import with %r", exc, type='sphinx_autodoc_typehints', subtype='guarded_import')
508+
_LOGGER.warning(
509+
"Failed guarded type import with %r", exc, type="sphinx_autodoc_typehints", subtype="guarded_import"
510+
)
504511

505512

506513
def _resolve_type_guarded_imports(autodoc_mock_imports: list[str], obj: Any) -> None:
@@ -536,7 +543,13 @@ def _get_type_hint(
536543
else:
537544
result = {}
538545
except NameError as exc:
539-
_LOGGER.warning('Cannot resolve forward reference in type annotations of "%s": %s', name, exc, type='sphinx_autodoc_typehints', subtype='forward_reference')
546+
_LOGGER.warning(
547+
'Cannot resolve forward reference in type annotations of "%s": %s',
548+
name,
549+
exc,
550+
type="sphinx_autodoc_typehints",
551+
subtype="forward_reference",
552+
)
540553
result = obj.__annotations__
541554
return result
542555

@@ -554,7 +567,12 @@ def backfill_type_hints(obj: Any, name: str) -> dict[str, Any]: # noqa: C901, P
554567
def _one_child(module: Module) -> stmt | None:
555568
children = module.body # use the body to ignore type comments
556569
if len(children) != 1:
557-
_LOGGER.warning('Did not get exactly one node from AST for "%s", got %s', name, len(children), type='sphinx_autodoc_typehints')
570+
_LOGGER.warning(
571+
'Did not get exactly one node from AST for "%s", got %s',
572+
name,
573+
len(children),
574+
type="sphinx_autodoc_typehints",
575+
)
558576
return None
559577
return children[0]
560578

@@ -579,7 +597,12 @@ def _one_child(module: Module) -> stmt | None:
579597
try:
580598
comment_args_str, comment_returns = type_comment.split(" -> ")
581599
except ValueError:
582-
_LOGGER.warning('Unparseable type hint comment for "%s": Expected to contain ` -> `', name, type='sphinx_autodoc_typehints', subtype='comment')
600+
_LOGGER.warning(
601+
'Unparseable type hint comment for "%s": Expected to contain ` -> `',
602+
name,
603+
type="sphinx_autodoc_typehints",
604+
subtype="comment",
605+
)
583606
return {}
584607

585608
rv = {}
@@ -594,7 +617,9 @@ def _one_child(module: Module) -> stmt | None:
594617
comment_args.insert(0, None) # self/cls may be omitted in type comments, insert blank
595618

596619
if len(args) != len(comment_args):
597-
_LOGGER.warning('Not enough type comments found on "%s"', name, type='sphinx_autodoc_typehints', subtype='comment')
620+
_LOGGER.warning(
621+
'Not enough type comments found on "%s"', name, type="sphinx_autodoc_typehints", subtype="comment"
622+
)
598623
return rv
599624

600625
for at, arg in enumerate(args):

0 commit comments

Comments
 (0)