Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Oct 31, 2023
1 parent c4bc8c1 commit 3554d79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/scanpydoc/elegant_typehints/_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from types import UnionType
from typing import TYPE_CHECKING, Any, Literal, Union, get_args, get_origin
from typing import Callable as t_Callable
from typing import Dict as t_Dict # noqa: UP035
from typing import Mapping as t_Mapping # noqa: UP035

from docutils import nodes
Expand Down Expand Up @@ -64,7 +65,7 @@ def _format_terse(annotation: type[Any], config: Config) -> str:
return f":py:class:`{tilde}collections.abc.Mapping`"

# display dict as {k: v}
if origin is dict and len(args) == 2: # noqa: PLR2004
if origin in (dict, t_Dict) and len(args) == 2: # noqa: UP006, PLR2004
k, v = args
return f"{{{fmt(k)}: {fmt(v)}}}"

Expand Down
13 changes: 7 additions & 6 deletions src/scanpydoc/elegant_typehints/_return_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import inspect
import re
from collections.abc import Collection
from logging import getLogger
from typing import TYPE_CHECKING, Any, get_args, get_origin, get_type_hints
from types import UnionType
from typing import TYPE_CHECKING, Any, Union, get_args, get_origin, get_type_hints
from typing import Tuple as t_Tuple # noqa: UP035

from ._formatting import format_both


if TYPE_CHECKING:
from collections.abc import Collection

from sphinx.application import Sphinx
from sphinx.ext.autodoc import Options

Expand All @@ -19,17 +22,15 @@


def get_tuple_annot(annotation: type | None) -> tuple[type, ...] | None:
from typing import Union

if annotation is None:
return None
origin = get_origin(annotation)
if not origin:
return None
if origin is Union:
if origin in (Union, UnionType):
for annot in get_args(annotation):
origin = get_origin(annot)
if origin in (tuple, tuple):
if origin in (tuple, t_Tuple): # noqa: UP006
annotation = annot
break
else:
Expand Down

0 comments on commit 3554d79

Please sign in to comment.