From b25deb259e55a1296332d32712676a2988d7fb06 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 7 Jan 2019 22:43:25 +0900 Subject: [PATCH] refactor: Move NoneType to sphinx.util.typing --- CHANGES | 1 + doc/extdev/index.rst | 5 +++++ sphinx/config.py | 3 ++- sphinx/util/inspect.py | 2 +- sphinx/util/pycompat.py | 5 ++--- sphinx/util/typing.py | 3 +++ 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index b1f4bcd2b..09465b56d 100644 --- a/CHANGES +++ b/CHANGES @@ -120,6 +120,7 @@ Deprecated * ``sphinx.util.osutil.EPIPE`` * ``sphinx.util.osutil.walk()`` * ``sphinx.util.PeekableIterator`` +* ``sphinx.util.pycompat.NoneType`` * ``sphinx.util.pycompat.TextIOWrapper`` * ``sphinx.util.pycompat.UnicodeMixin`` * ``sphinx.util.pycompat.htmlescape`` diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst index 719fb3e66..d650554d1 100644 --- a/doc/extdev/index.rst +++ b/doc/extdev/index.rst @@ -420,6 +420,11 @@ The following is a list of deprecated interfaces. - 4.0 - ``os.walk()`` + * - ``sphinx.util.pycompat.NoneType`` + - 2.0 + - 4.0 + - ``sphinx.util.typing.NoneType`` + * - ``sphinx.util.pycompat.TextIOWrapper`` - 2.0 - 4.0 diff --git a/sphinx/config.py b/sphinx/config.py index e4087385f..f844549da 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -22,7 +22,8 @@ from sphinx.locale import _, __ from sphinx.util import logging from sphinx.util.i18n import format_date from sphinx.util.osutil import cd -from sphinx.util.pycompat import execfile_, NoneType +from sphinx.util.pycompat import execfile_ +from sphinx.util.typing import NoneType if False: # For type annotation diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index d4c0f1948..89dd842e3 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -20,7 +20,7 @@ from io import StringIO from sphinx.deprecation import RemovedInSphinx30Warning from sphinx.util import logging -from sphinx.util.pycompat import NoneType +from sphinx.util.typing import NoneType if False: # For type annotation diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 51697432e..ddacd0a8e 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -18,7 +18,7 @@ from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias from sphinx.locale import __ from sphinx.util import logging from sphinx.util.console import terminal_safe - +from sphinx.util.typing import NoneType if False: # For type annotation @@ -28,8 +28,6 @@ if False: logger = logging.getLogger(__name__) -NoneType = type(None) - # ------------------------------------------------------------------------------ # Python 2/3 compatibility @@ -95,6 +93,7 @@ def execfile_(filepath, _globals, open=open): deprecated_alias('sphinx.util.pycompat', { + 'NoneType': NoneType, # type: ignore 'TextIOWrapper': io.TextIOWrapper, 'htmlescape': html.escape, 'indent': textwrap.indent, diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index 6fb729458..78e8fe61f 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -20,6 +20,9 @@ DirectiveOption = Callable[[str], Any] # Text like nodes which are initialized with text and rawsource TextlikeNode = Union[nodes.Text, nodes.TextElement] +# type of None +NoneType = type(None) + # common role functions RoleFunction = Callable[[str, str, str, int, Inliner, Dict, List[str]], Tuple[List[nodes.Node], List[nodes.system_message]]]