Skip to content

Commit

Permalink
Update to mypy 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Apr 25, 2024
1 parent 3edf2a2 commit 7953798
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ docs = [
lint = [
"flake8>=3.5.0",
"ruff==0.4.1",
"mypy==1.9.0",
"mypy==1.10.0",
"sphinx-lint",
"types-docutils",
"types-requests",
Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/autodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,7 @@ def import_object(self, raiseerror: bool = False) -> bool:
obj = __dict__.get(self.objpath[-1])
if isinstance(obj, classmethod) and inspect.isproperty(obj.__func__):
self.object = obj.__func__
self.isclassmethod = True
self.isclassmethod: bool = True
return True
else:
return False
Expand Down
4 changes: 2 additions & 2 deletions sphinx/ext/autodoc/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from collections.abc import Iterator, Sequence
from typing import Any

from typing_extensions import TypeGuard
from typing_extensions import TypeIs

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -156,7 +156,7 @@ def mock(modnames: list[str]) -> Iterator[None]:
finder.invalidate_caches()


def ismockmodule(subject: Any) -> TypeGuard[_MockModule]:
def ismockmodule(subject: Any) -> TypeIs[_MockModule]:
"""Check if the object is a mocked module."""
return isinstance(subject, _MockModule)

Expand Down
28 changes: 14 additions & 14 deletions sphinx/util/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from types import MethodType, ModuleType
from typing import Final, Protocol, Union

from typing_extensions import TypeAlias, TypeGuard
from typing_extensions import TypeAlias, TypeIs

class _SupportsGet(Protocol):
def __get__(self, __instance: Any, __owner: type | None = ...) -> Any: ... # NoQA: E704
Expand Down Expand Up @@ -213,12 +213,12 @@ def isNewType(obj: Any) -> bool:
return __module__ == 'typing' and __qualname__ == 'NewType.<locals>.new_type'


def isenumclass(x: Any) -> TypeGuard[type[enum.Enum]]:
def isenumclass(x: Any) -> TypeIs[type[enum.Enum]]:
"""Check if the object is an :class:`enumeration class <enum.Enum>`."""
return isclass(x) and issubclass(x, enum.Enum)


def isenumattribute(x: Any) -> TypeGuard[enum.Enum]:
def isenumattribute(x: Any) -> TypeIs[enum.Enum]:
"""Check if the object is an enumeration attribute."""
return isinstance(x, enum.Enum)

Expand All @@ -235,7 +235,7 @@ def unpartial(obj: Any) -> Any:
return obj


def ispartial(obj: Any) -> TypeGuard[partial | partialmethod]:
def ispartial(obj: Any) -> TypeIs[partial | partialmethod]:
"""Check if the object is a partial function or method."""
return isinstance(obj, (partial, partialmethod))

Expand All @@ -244,7 +244,7 @@ def isclassmethod(
obj: Any,
cls: Any = None,
name: str | None = None,
) -> TypeGuard[classmethod]:
) -> TypeIs[classmethod]:
"""Check if the object is a :class:`classmethod`."""
if isinstance(obj, classmethod):
return True
Expand All @@ -264,7 +264,7 @@ def isstaticmethod(
obj: Any,
cls: Any = None,
name: str | None = None,
) -> TypeGuard[staticmethod]:
) -> TypeIs[staticmethod]:
"""Check if the object is a :class:`staticmethod`."""
if isinstance(obj, staticmethod):
return True
Expand All @@ -278,7 +278,7 @@ def isstaticmethod(
return False


def isdescriptor(x: Any) -> TypeGuard[_SupportsGet | _SupportsSet | _SupportsDelete]:
def isdescriptor(x: Any) -> TypeIs[_SupportsGet | _SupportsSet | _SupportsDelete]:
"""Check if the object is a :external+python:term:`descriptor`."""
return any(
callable(safe_getattr(x, item, None)) for item in ('__get__', '__set__', '__delete__')
Expand Down Expand Up @@ -345,12 +345,12 @@ def is_singledispatch_function(obj: Any) -> bool:
)


def is_singledispatch_method(obj: Any) -> TypeGuard[singledispatchmethod]:
def is_singledispatch_method(obj: Any) -> TypeIs[singledispatchmethod]:
"""Check if the object is a :class:`~functools.singledispatchmethod`."""
return isinstance(obj, singledispatchmethod)


def isfunction(obj: Any) -> TypeGuard[types.FunctionType]:
def isfunction(obj: Any) -> TypeIs[types.FunctionType]:
"""Check if the object is a user-defined function.
Partial objects are unwrapped before checking them.
Expand All @@ -360,7 +360,7 @@ def isfunction(obj: Any) -> TypeGuard[types.FunctionType]:
return inspect.isfunction(unpartial(obj))


def isbuiltin(obj: Any) -> TypeGuard[types.BuiltinFunctionType]:
def isbuiltin(obj: Any) -> TypeIs[types.BuiltinFunctionType]:
"""Check if the object is a built-in function or method.
Partial objects are unwrapped before checking them.
Expand All @@ -370,7 +370,7 @@ def isbuiltin(obj: Any) -> TypeGuard[types.BuiltinFunctionType]:
return inspect.isbuiltin(unpartial(obj))


def isroutine(obj: Any) -> TypeGuard[_RoutineType]:
def isroutine(obj: Any) -> TypeIs[_RoutineType]:
"""Check if the object is a kind of function or method.
Partial objects are unwrapped before checking them.
Expand All @@ -380,7 +380,7 @@ def isroutine(obj: Any) -> TypeGuard[_RoutineType]:
return inspect.isroutine(unpartial(obj))


def iscoroutinefunction(obj: Any) -> TypeGuard[Callable[..., types.CoroutineType]]:
def iscoroutinefunction(obj: Any) -> TypeIs[Callable[..., types.CoroutineType]]:
"""Check if the object is a :external+python:term:`coroutine` function."""
obj = unwrap_all(obj, stop=_is_wrapped_coroutine)
return inspect.iscoroutinefunction(obj)
Expand All @@ -395,12 +395,12 @@ def _is_wrapped_coroutine(obj: Any) -> bool:
return hasattr(obj, '__wrapped__')


def isproperty(obj: Any) -> TypeGuard[property | cached_property]:
def isproperty(obj: Any) -> TypeIs[property | cached_property]:
"""Check if the object is property (possibly cached)."""
return isinstance(obj, (property, cached_property))


def isgenericalias(obj: Any) -> TypeGuard[types.GenericAlias]:
def isgenericalias(obj: Any) -> TypeIs[types.GenericAlias]:
"""Check if the object is a generic alias."""
return isinstance(obj, (types.GenericAlias, typing._BaseGenericAlias)) # type: ignore[attr-defined]

Expand Down
6 changes: 3 additions & 3 deletions sphinx/util/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from collections.abc import Mapping
from typing import Final, Literal

from typing_extensions import TypeAlias, TypeGuard
from typing_extensions import TypeAlias, TypeIs

from sphinx.application import Sphinx

Expand Down Expand Up @@ -173,7 +173,7 @@ def is_system_TypeVar(typ: Any) -> bool:
return modname == 'typing' and isinstance(typ, TypeVar)


def _is_annotated_form(obj: Any) -> TypeGuard[Annotated[Any, ...]]:
def _is_annotated_form(obj: Any) -> TypeIs[Annotated[Any, ...]]:
"""Check if *obj* is an annotated type."""
return typing.get_origin(obj) is Annotated or str(obj).startswith('typing.Annotated')

Expand Down Expand Up @@ -255,7 +255,7 @@ def restify(cls: Any, mode: _RestifyMode = 'fully-qualified-except-typing') -> s
cls_name = _typing_internal_name(cls)

if isinstance(cls.__origin__, typing._SpecialForm):
# ClassVar; Concatenate; Final; Literal; Unpack; TypeGuard
# ClassVar; Concatenate; Final; Literal; Unpack; TypeGuard; TypeIs
# Required/NotRequired
text = restify(cls.__origin__, mode)
elif cls_name:
Expand Down

0 comments on commit 7953798

Please sign in to comment.