diff --git a/pyproject.toml b/pyproject.toml index 14ca5d092be..21cf38b0baf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,7 +86,7 @@ lint = [ "flake8-bugbear", "flake8-simplify", "isort", - "mypy>=0.971", + "mypy>=0.981", "sphinx-lint", "docutils-stubs", "types-typed-ast", diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 68cab115c9b..c6a05875f08 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -47,7 +47,7 @@ class GenericObject(ObjectDescription[str]): A generic x-ref directive registered with Sphinx.add_object_type(). """ indextemplate: str = '' - parse_node: Callable[["GenericObject", "BuildEnvironment", str, desc_signature], str] = None # NOQA + parse_node: Callable[["BuildEnvironment", str, desc_signature], str] = None # NOQA def handle_signature(self, sig: str, signode: desc_signature) -> str: if self.parse_node: diff --git a/sphinx/util/parallel.py b/sphinx/util/parallel.py index 267f7bd4c18..16a95e0397b 100644 --- a/sphinx/util/parallel.py +++ b/sphinx/util/parallel.py @@ -19,10 +19,11 @@ logger = logging.getLogger(__name__) if sys.platform != "win32": + ForkContext = multiprocessing.context.ForkContext ForkProcess = multiprocessing.context.ForkProcess else: # For static typing, as ForkProcess doesn't exist on Windows - ForkProcess = multiprocessing.process.BaseProcess + ForkContext = ForkProcess = Any # our parallel functionality only works for the forking Process parallel_available = multiprocessing and os.name == 'posix' @@ -92,7 +93,7 @@ def add_task( self._result_funcs[tid] = result_func or (lambda arg, result: None) self._args[tid] = arg precv, psend = multiprocessing.Pipe(False) - context = multiprocessing.get_context('fork') + context: ForkContext = multiprocessing.get_context('fork') proc = context.Process(target=self._process, args=(psend, task_func, arg)) self._procs[tid] = proc self._precvsWaiting[tid] = precv diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index 518ea8771ae..c57cb7c5cf9 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -267,7 +267,7 @@ def _restify_py36(cls: Optional[Type], mode: str = 'fully-qualified-except-typin return reftext + '\\ [%s]' % param_str else: return reftext - elif isinstance(cls, typing.GenericMeta): + elif isinstance(cls, typing.GenericMeta): # type: ignore[attr-defined] if module == 'typing': reftext = ':py:class:`~typing.%s`' % qualname else: @@ -505,16 +505,16 @@ def _stringify_py36(annotation: Any, mode: str = 'fully-qualified-except-typing' return '%s%s[%s]' % (modprefix, qualname, param_str) else: return modprefix + qualname - elif isinstance(annotation, typing.GenericMeta): + elif isinstance(annotation, typing.GenericMeta): # type: ignore[attr-defined] params = None - if annotation.__args__ is None or len(annotation.__args__) <= 2: # type: ignore # NOQA - params = annotation.__args__ # type: ignore - elif annotation.__origin__ == Generator: # type: ignore - params = annotation.__args__ # type: ignore + if annotation.__args__ is None or len(annotation.__args__) <= 2: # NOQA + params = annotation.__args__ + elif annotation.__origin__ == Generator: + params = annotation.__args__ else: # typing.Callable args = ', '.join(stringify(arg, mode) for arg - in annotation.__args__[:-1]) # type: ignore - result = stringify(annotation.__args__[-1]) # type: ignore + in annotation.__args__[:-1]) + result = stringify(annotation.__args__[-1]) return '%s%s[[%s], %s]' % (modprefix, qualname, args, result) if params is not None: param_str = ', '.join(stringify(p, mode) for p in params)