Skip to content

Commit

Permalink
Fix type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
jl-wynen committed Jan 24, 2024
1 parent 47b417a commit be4ab9f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/sciline/sphinxext/domain_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def setup(app: Sphinx) -> dict[str, Any]:
}


def _typehints_formatter(annotation, config: Config) -> Optional[str]:
def _typehints_formatter(annotation: Any, config: Config) -> Optional[str]:
"""Format typehints with improved NewType handling."""
prefix = config.sciline_domain_types_prefix
aliases = _DEFAULT_ALIASES | config.sciline_domain_types_extra_aliases
Expand All @@ -92,7 +92,7 @@ def _is_new_type(annotation: Any) -> bool:
return hasattr(annotation, '__supertype__')


def _format_new_type(annotation: NewType, prefix: str, aliases: dict[str, str]) -> str:
def _format_new_type(annotation: Any, prefix: str, aliases: dict[str, str]) -> str:
return (
f'{_internal_link(annotation, "class", prefix)}'
f' ({_link(annotation.__supertype__, "class",aliases)})'
Expand All @@ -101,7 +101,7 @@ def _format_new_type(annotation: NewType, prefix: str, aliases: dict[str, str])

def _is_type_alias_type(annotation: Any) -> bool:
try:
from typing import TypeAliasType
from typing import TypeAliasType # type: ignore[attr-defined]

return isinstance(annotation, TypeAliasType)
except ImportError:
Expand All @@ -118,10 +118,10 @@ def _format_type_alias_type(
return f'{alias} ({value})'


def _get_type_args(ty: type) -> tuple[type, ...]:
def _get_type_args(ty: Any) -> tuple[type, ...]:
if (args := getattr(ty, '__args__', None)) is not None:
return args # e.g. list[int]
return ty.__type_params__
return args # type: ignore[no-any-return] # e.g. list[int]
return ty.__type_params__ # type: ignore[no-any-return]


def _internal_link(
Expand Down

0 comments on commit be4ab9f

Please sign in to comment.