Skip to content

Commit 7953798

Browse files
committed
Update to mypy 1.10
1 parent 3edf2a2 commit 7953798

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ docs = [
8484
lint = [
8585
"flake8>=3.5.0",
8686
"ruff==0.4.1",
87-
"mypy==1.9.0",
87+
"mypy==1.10.0",
8888
"sphinx-lint",
8989
"types-docutils",
9090
"types-requests",

sphinx/ext/autodoc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2773,7 +2773,7 @@ def import_object(self, raiseerror: bool = False) -> bool:
27732773
obj = __dict__.get(self.objpath[-1])
27742774
if isinstance(obj, classmethod) and inspect.isproperty(obj.__func__):
27752775
self.object = obj.__func__
2776-
self.isclassmethod = True
2776+
self.isclassmethod: bool = True
27772777
return True
27782778
else:
27792779
return False

sphinx/ext/autodoc/mock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from collections.abc import Iterator, Sequence
1818
from typing import Any
1919

20-
from typing_extensions import TypeGuard
20+
from typing_extensions import TypeIs
2121

2222
logger = logging.getLogger(__name__)
2323

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

158158

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

sphinx/util/inspect.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from types import MethodType, ModuleType
3030
from typing import Final, Protocol, Union
3131

32-
from typing_extensions import TypeAlias, TypeGuard
32+
from typing_extensions import TypeAlias, TypeIs
3333

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

215215

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

220220

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

@@ -235,7 +235,7 @@ def unpartial(obj: Any) -> Any:
235235
return obj
236236

237237

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

@@ -244,7 +244,7 @@ def isclassmethod(
244244
obj: Any,
245245
cls: Any = None,
246246
name: str | None = None,
247-
) -> TypeGuard[classmethod]:
247+
) -> TypeIs[classmethod]:
248248
"""Check if the object is a :class:`classmethod`."""
249249
if isinstance(obj, classmethod):
250250
return True
@@ -264,7 +264,7 @@ def isstaticmethod(
264264
obj: Any,
265265
cls: Any = None,
266266
name: str | None = None,
267-
) -> TypeGuard[staticmethod]:
267+
) -> TypeIs[staticmethod]:
268268
"""Check if the object is a :class:`staticmethod`."""
269269
if isinstance(obj, staticmethod):
270270
return True
@@ -278,7 +278,7 @@ def isstaticmethod(
278278
return False
279279

280280

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

347347

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

352352

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

362362

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

372372

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

382382

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

397397

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

402402

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

sphinx/util/typing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from collections.abc import Mapping
2727
from typing import Final, Literal
2828

29-
from typing_extensions import TypeAlias, TypeGuard
29+
from typing_extensions import TypeAlias, TypeIs
3030

3131
from sphinx.application import Sphinx
3232

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

175175

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

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

257257
if isinstance(cls.__origin__, typing._SpecialForm):
258-
# ClassVar; Concatenate; Final; Literal; Unpack; TypeGuard
258+
# ClassVar; Concatenate; Final; Literal; Unpack; TypeGuard; TypeIs
259259
# Required/NotRequired
260260
text = restify(cls.__origin__, mode)
261261
elif cls_name:

0 commit comments

Comments
 (0)