From c8c7fee4e5acf9b43bb928a3d98fcc9049da7ef1 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 23 Jul 2024 01:31:53 +0100 Subject: [PATCH] Use ``types.NoneType`` (#12659) --- sphinx/builders/__init__.py | 3 +-- sphinx/config.py | 7 +++---- sphinx/util/typing.py | 7 ++----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 076af8af5..afbc0568a 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -38,7 +38,6 @@ if TYPE_CHECKING: from sphinx.config import Config from sphinx.events import EventManager from sphinx.util.tags import Tags - from sphinx.util.typing import NoneType logger = logging.getLogger(__name__) @@ -645,7 +644,7 @@ class Builder: progress = status_iterator(chunks, __('writing output... '), "darkgreen", len(chunks), self.app.verbosity) - def on_chunk_done(args: list[tuple[str, NoneType]], result: NoneType) -> None: + def on_chunk_done(args: list[tuple[str, nodes.document]], result: None) -> None: next(progress) self.app.phase = BuildPhase.RESOLVING diff --git a/sphinx/config.py b/sphinx/config.py index 58b6d6e0f..b330d29b5 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -15,7 +15,6 @@ from sphinx.errors import ConfigError, ExtensionError from sphinx.locale import _, __ from sphinx.util import logging from sphinx.util.osutil import fs_encoding -from sphinx.util.typing import ExtensionMetadata, NoneType if sys.version_info >= (3, 11): from contextlib import chdir @@ -30,7 +29,7 @@ if TYPE_CHECKING: from sphinx.application import Sphinx from sphinx.environment import BuildEnvironment from sphinx.util.tags import Tags - from sphinx.util.typing import _ExtensionSetupFunc + from sphinx.util.typing import ExtensionMetadata, _ExtensionSetupFunc logger = logging.getLogger(__name__) @@ -250,7 +249,7 @@ class Config: 'rst_epilog': _Opt(None, 'env', frozenset((str,))), 'rst_prolog': _Opt(None, 'env', frozenset((str,))), 'trim_doctest_flags': _Opt(True, 'env', ()), - 'primary_domain': _Opt('py', 'env', frozenset((NoneType,))), + 'primary_domain': _Opt('py', 'env', frozenset((types.NoneType,))), 'needs_sphinx': _Opt(None, '', frozenset((str,))), 'needs_extensions': _Opt({}, '', ()), 'manpages_url': _Opt(None, 'env', ()), @@ -261,7 +260,7 @@ class Config: 'numfig_secnum_depth': _Opt(1, 'env', ()), 'numfig_format': _Opt({}, 'env', ()), # will be initialized in init_numfig_format() 'maximum_signature_line_length': _Opt( - None, 'env', frozenset((int, NoneType))), + None, 'env', frozenset((int, types.NoneType))), 'math_number_all': _Opt(False, 'env', ()), 'math_eqref_format': _Opt(None, 'env', frozenset((str,))), 'math_numfig': _Opt(True, 'env', ()), diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index 97ee5bd92..004fa0f9c 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -83,9 +83,6 @@ def is_invalid_builtin_class(obj: Any) -> bool: # Text like nodes which are initialized with text and rawsource TextlikeNode: TypeAlias = nodes.Text | nodes.TextElement -# type of None -NoneType: TypeAlias = type(None) # type: ignore[no-redef] - # path matcher PathMatcher: TypeAlias = Callable[[str], bool] @@ -237,7 +234,7 @@ def restify(cls: Any, mode: _RestifyMode = 'fully-qualified-except-typing') -> s raise ValueError(msg) # things that are not types - if cls is None or cls == NoneType: + if cls is None or cls == types.NoneType: return ':py:obj:`None`' if cls is Ellipsis: return '...' @@ -397,7 +394,7 @@ def stringify_annotation( raise ValueError(msg) # things that are not types - if annotation is None or annotation == NoneType: + if annotation is None or annotation == types.NoneType: return 'None' if annotation is Ellipsis: return '...'