diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-03-07 10:45:39 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-03-07 19:36:41 +0900 |
commit | 6d4fefebf4ecee4416da016d8e647298003fb57a (patch) | |
tree | a0f8dedd36b9562a248bcf8bc8eab91d09136a58 | |
parent | 3e0618ba3a84c7db51813cab43779d11c5fe7802 (diff) | |
download | sphinx-git-6d4fefebf4ecee4416da016d8e647298003fb57a.tar.gz |
Deprecate codes for python 3.5
32 files changed, 42 insertions, 144 deletions
diff --git a/sphinx/application.py b/sphinx/application.py index fbc637e60..a24bd9bb9 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -18,7 +18,7 @@ import warnings from collections import deque from io import StringIO from os import path -from typing import Any, Callable, Dict, IO, List, Tuple, Union +from typing import Any, Callable, Dict, IO, List, Tuple, Type, Union from docutils import nodes from docutils.nodes import Element, TextElement @@ -56,7 +56,6 @@ from sphinx.util.typing import RoleFunction, TitleGetter if False: # For type annotation from docutils.nodes import Node # NOQA - from typing import Type # for python3.5.1 from sphinx.builders import Builder diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index c596df3c5..1d43080df 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -11,7 +11,7 @@ import pickle import time from os import path -from typing import Any, Dict, Iterable, List, Sequence, Set, Tuple, Union +from typing import Any, Dict, Iterable, List, Sequence, Set, Tuple, Type, Union from docutils import nodes from docutils.nodes import Node @@ -44,7 +44,6 @@ except ImportError: if False: # For type annotation - from typing import Type # for python3.5.1 from sphinx.application import Sphinx diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index 65f112510..3fb7595ee 100644 --- a/sphinx/builders/gettext.py +++ b/sphinx/builders/gettext.py @@ -13,7 +13,7 @@ from collections import defaultdict, OrderedDict from datetime import datetime, tzinfo, timedelta from os import path, walk, getenv from time import time -from typing import Any, Dict, Iterable, Generator, List, Set, Tuple, Union +from typing import Any, DefaultDict, Dict, Iterable, Generator, List, Set, Tuple, Union from uuid import uuid4 from docutils import nodes @@ -34,10 +34,6 @@ from sphinx.util.osutil import ensuredir, canon_path, relpath from sphinx.util.tags import Tags from sphinx.util.template import SphinxRenderer -if False: - # For type annotation - from typing import DefaultDict # for python3.5.1 - logger = logging.getLogger(__name__) POHEADER = r""" diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index cf8cd56ce..8c91f9a70 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -15,7 +15,7 @@ import sys import warnings from hashlib import md5 from os import path -from typing import Any, Dict, IO, Iterable, Iterator, List, Set, Tuple +from typing import Any, Dict, IO, Iterable, Iterator, List, Set, Tuple, Type from docutils import nodes from docutils.core import publish_parts @@ -48,10 +48,6 @@ from sphinx.util.osutil import os_path, relative_uri, ensuredir, movefile, copyf from sphinx.util.tags import Tags from sphinx.writers.html import HTMLWriter, HTMLTranslator -if False: - # For type annotation - from typing import Type # for python3.5.1 - # HTML5 Writer is available or not if is_html5_writer_available(): diff --git a/sphinx/builders/xml.py b/sphinx/builders/xml.py index 81d729def..d5fd6b40a 100644 --- a/sphinx/builders/xml.py +++ b/sphinx/builders/xml.py @@ -9,7 +9,7 @@ """ from os import path -from typing import Any, Dict, Iterator, Set, Union +from typing import Any, Dict, Iterator, Set, Type, Union from docutils import nodes from docutils.io import StringOutput @@ -23,10 +23,6 @@ from sphinx.util import logging from sphinx.util.osutil import ensuredir, os_path from sphinx.writers.xml import XMLWriter, PseudoXMLWriter -if False: - # For type annotation - from typing import Type # for python3.5.1 - logger = logging.getLogger(__name__) diff --git a/sphinx/deprecation.py b/sphinx/deprecation.py index e9510bde4..a1b024c09 100644 --- a/sphinx/deprecation.py +++ b/sphinx/deprecation.py @@ -11,8 +11,7 @@ import sys import warnings from importlib import import_module -from typing import Any, Dict -from typing import Type # for python3.5.1 +from typing import Any, Dict, Type class RemovedInSphinx40Warning(DeprecationWarning): diff --git a/sphinx/domains/__init__.py b/sphinx/domains/__init__.py index 11b3a4604..11f0d208c 100644 --- a/sphinx/domains/__init__.py +++ b/sphinx/domains/__init__.py @@ -10,7 +10,7 @@ """ import copy -from typing import Any, Callable, Dict, Iterable, List, NamedTuple, Tuple, Union +from typing import Any, Callable, Dict, Iterable, List, NamedTuple, Tuple, Type, Union from typing import cast from docutils import nodes @@ -25,7 +25,6 @@ from sphinx.util.typing import RoleFunction if False: # For type annotation - from typing import Type # for python3.5.1 from sphinx.builders import Builder from sphinx.environment import BuildEnvironment diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index e667f91dc..eb5613c64 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -14,7 +14,7 @@ import re import typing import warnings from inspect import Parameter -from typing import Any, Dict, Iterable, Iterator, List, Tuple +from typing import Any, Dict, Iterable, Iterator, List, Tuple, Type from typing import cast from docutils import nodes @@ -38,10 +38,6 @@ from sphinx.util.inspect import signature_from_str from sphinx.util.nodes import make_id, make_refnode from sphinx.util.typing import TextlikeNode -if False: - # For type annotation - from typing import Type # for python3.5.1 - logger = logging.getLogger(__name__) diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index b2538f034..0fa93dd23 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -12,7 +12,7 @@ import re import unicodedata import warnings from copy import copy -from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union +from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Type, Union from typing import cast from docutils import nodes @@ -34,7 +34,6 @@ from sphinx.util.typing import RoleFunction if False: # For type annotation - from typing import Type # for python3.5.1 from sphinx.application import Sphinx from sphinx.builders import Builder from sphinx.environment import BuildEnvironment diff --git a/sphinx/environment/collectors/toctree.py b/sphinx/environment/collectors/toctree.py index e168bd9c4..acb45ef56 100644 --- a/sphinx/environment/collectors/toctree.py +++ b/sphinx/environment/collectors/toctree.py @@ -8,7 +8,7 @@ :license: BSD, see LICENSE for details. """ -from typing import Any, Dict, List, Set, Tuple, TypeVar +from typing import Any, Dict, List, Set, Tuple, Type, TypeVar from typing import cast from docutils import nodes @@ -23,10 +23,6 @@ from sphinx.locale import __ from sphinx.transforms import SphinxContentsFilter from sphinx.util import url_re, logging -if False: - # For type annotation - from typing import Type # for python3.5.1 - N = TypeVar('N') diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 7abd6c879..025d4a091 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -14,7 +14,7 @@ import importlib import re import warnings from types import ModuleType -from typing import Any, Callable, Dict, Iterator, List, Sequence, Set, Tuple, Union +from typing import Any, Callable, Dict, Iterator, List, Sequence, Set, Tuple, Type, Union from docutils.statemachine import StringList @@ -36,7 +36,6 @@ from sphinx.util.typing import stringify as stringify_typehint if False: # For type annotation - from typing import Type # NOQA # for python3.5.1 from sphinx.ext.autodoc.directive import DocumenterBridge @@ -262,7 +261,7 @@ class Documenter: self.analyzer = None # type: ModuleAnalyzer @property - def documenters(self) -> Dict[str, "Type[Documenter]"]: + def documenters(self) -> Dict[str, Type["Documenter"]]: """Returns registered Documenter classes""" return get_documenters(self.env.app) @@ -1591,7 +1590,7 @@ class SlotsAttributeDocumenter(AttributeDocumenter): return [] -def get_documenters(app: Sphinx) -> Dict[str, "Type[Documenter]"]: +def get_documenters(app: Sphinx) -> Dict[str, Type[Documenter]]: """Returns registered Documenter classes""" return app.registry.documenters diff --git a/sphinx/ext/autodoc/directive.py b/sphinx/ext/autodoc/directive.py index b44bd75b3..3fe5dc950 100644 --- a/sphinx/ext/autodoc/directive.py +++ b/sphinx/ext/autodoc/directive.py @@ -7,7 +7,7 @@ """ import warnings -from typing import Any, Callable, Dict, List, Set +from typing import Any, Callable, Dict, List, Set, Type from docutils import nodes from docutils.nodes import Element, Node @@ -23,10 +23,6 @@ from sphinx.util import logging from sphinx.util.docutils import SphinxDirective, switch_source_input from sphinx.util.nodes import nested_parse_with_titles -if False: - # For type annotation - from typing import Type # for python3.5.1 - logger = logging.getLogger(__name__) diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index 3d296cbde..7d2109abb 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -60,7 +60,7 @@ import sys import warnings from os import path from types import ModuleType -from typing import Any, Dict, List, Tuple +from typing import Any, Dict, List, Tuple, Type from typing import cast from docutils import nodes @@ -88,10 +88,6 @@ from sphinx.util.docutils import ( from sphinx.util.matching import Matcher from sphinx.writers.html import HTMLTranslator -if False: - # For type annotation - from typing import Type # for python3.5.1 - logger = logging.getLogger(__name__) diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py index ef623e2bd..10865749d 100644 --- a/sphinx/ext/autosummary/generate.py +++ b/sphinx/ext/autosummary/generate.py @@ -24,7 +24,7 @@ import pydoc import re import sys import warnings -from typing import Any, Callable, Dict, List, Set, Tuple +from typing import Any, Callable, Dict, List, Set, Tuple, Type from jinja2 import BaseLoader, FileSystemLoader, TemplateNotFound from jinja2.sandbox import SandboxedEnvironment @@ -44,10 +44,6 @@ from sphinx.util import rst from sphinx.util.inspect import safe_getattr from sphinx.util.osutil import ensuredir -if False: - # For type annotation - from typing import Type # for python3.5.1 - logger = logging.getLogger(__name__) diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index 645521f9b..f20e840ec 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -16,7 +16,7 @@ import time import warnings from io import StringIO from os import path -from typing import Any, Callable, Dict, Iterable, List, Sequence, Set, Tuple +from typing import Any, Callable, Dict, Iterable, List, Sequence, Set, Tuple, Type from docutils import nodes from docutils.nodes import Element, Node, TextElement @@ -35,7 +35,6 @@ from sphinx.util.osutil import relpath if False: # For type annotation - from typing import Type # for python3.5.1 from sphinx.application import Sphinx diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index 7f6ebe478..c490670be 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -13,17 +13,13 @@ import inspect import re from functools import partial -from typing import Any, Callable, Dict, List, Tuple, Union +from typing import Any, Callable, Dict, List, Tuple, Type, Union from sphinx.application import Sphinx from sphinx.config import Config as SphinxConfig from sphinx.ext.napoleon.iterators import modify_iter from sphinx.locale import _ -if False: - # For type annotation - from typing import Type # for python3.5.1 - _directive_regex = re.compile(r'\.\. \S+::') _google_section_regex = re.compile(r'^(\s|\w)+:\s*$') diff --git a/sphinx/io.py b/sphinx/io.py index 18b4f053e..0462afd83 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -9,8 +9,7 @@ """ import codecs import warnings -from typing import Any, List -from typing import Type # for python3.5.1 +from typing import Any, List, Type from docutils import nodes from docutils.core import Publisher diff --git a/sphinx/parsers.py b/sphinx/parsers.py index 3974d1c66..fb6c263c9 100644 --- a/sphinx/parsers.py +++ b/sphinx/parsers.py @@ -9,7 +9,7 @@ """ import warnings -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Type, Union import docutils.parsers import docutils.parsers.rst @@ -24,7 +24,6 @@ from sphinx.util.rst import append_epilog, prepend_prolog if False: # For type annotation from docutils.transforms import Transform # NOQA - from typing import Type # NOQA # for python3.5.1 from sphinx.application import Sphinx @@ -71,7 +70,7 @@ class Parser(docutils.parsers.Parser): class RSTParser(docutils.parsers.rst.Parser, Parser): """A reST parser for Sphinx.""" - def get_transforms(self) -> List["Type[Transform]"]: + def get_transforms(self) -> List[Type[Transform]]: """Sphinx's reST parser replaces a transform class for smart-quotes by own's refs: sphinx.io.SphinxStandaloneReader diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py index cb3cf0cc1..5b6bf4b7f 100644 --- a/sphinx/pycode/parser.py +++ b/sphinx/pycode/parser.py @@ -349,7 +349,7 @@ class VariableCommentPicker(ast.NodeVisitor): for varname in varnames: self.add_entry(varname) - def visit_AnnAssign(self, node: ast.AST) -> None: # Note: ast.AnnAssign not found in py35 + def visit_AnnAssign(self, node: ast.AnnAssign) -> None: """Handles AnnAssign node and pick up a variable comment.""" self.visit_Assign(node) # type: ignore diff --git a/sphinx/registry.py b/sphinx/registry.py index 93a7ebc25..d25c688c4 100644 --- a/sphinx/registry.py +++ b/sphinx/registry.py @@ -11,7 +11,7 @@ import traceback from importlib import import_module from types import MethodType -from typing import Any, Callable, Dict, Iterator, List, Tuple, Union +from typing import Any, Callable, Dict, Iterator, List, Tuple, Type, Union from docutils import nodes from docutils.io import Input @@ -37,7 +37,6 @@ from sphinx.util.typing import RoleFunction, TitleGetter if False: # For type annotation - from typing import Type # for python3.5.1 from sphinx.application import Sphinx from sphinx.ext.autodoc import Documenter diff --git a/sphinx/roles.py b/sphinx/roles.py index a42a5610d..45a628533 100644 --- a/sphinx/roles.py +++ b/sphinx/roles.py @@ -10,8 +10,7 @@ import re import warnings -from typing import Any, Dict, List, Tuple -from typing import Type # for python3.5.1 +from typing import Any, Dict, List, Tuple, Type from docutils import nodes, utils from docutils.nodes import Element, Node, TextElement, system_message diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py index aab4297a0..118bfcc55 100644 --- a/sphinx/search/__init__.py +++ b/sphinx/search/__init__.py @@ -13,7 +13,7 @@ import re import warnings from importlib import import_module from os import path -from typing import Any, Dict, IO, Iterable, List, Tuple, Set +from typing import Any, Dict, IO, Iterable, List, Tuple, Set, Type from docutils import nodes from docutils.nodes import Node @@ -25,10 +25,6 @@ from sphinx.environment import BuildEnvironment from sphinx.search.jssplitter import splitter_code from sphinx.util import jsdump, rpartition -if False: - # For type annotation - from typing import Type # for python3.5.1 - class SearchLanguage: """ diff --git a/sphinx/transforms/i18n.py b/sphinx/transforms/i18n.py index 34d5b1368..c889884af 100644 --- a/sphinx/transforms/i18n.py +++ b/sphinx/transforms/i18n.py @@ -10,7 +10,7 @@ from os import path from textwrap import indent -from typing import Any, Dict, List, Tuple, TypeVar +from typing import Any, Dict, List, Tuple, Type, TypeVar from docutils import nodes from docutils.io import StringInput @@ -31,7 +31,6 @@ from sphinx.util.nodes import ( if False: # For type annotation - from typing import Type # for python3.5.1 from sphinx.application import Sphinx diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 12ae051f1..186d48d2d 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -25,7 +25,7 @@ from hashlib import md5 from importlib import import_module from os import path from time import mktime, strptime -from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Pattern, Set, Tuple +from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Pattern, Set, Tuple, Type from urllib.parse import urlsplit, urlunsplit, quote_plus, parse_qsl, urlencode from sphinx.deprecation import RemovedInSphinx40Warning @@ -51,7 +51,6 @@ from sphinx.util.matching import patfilter # noqa if False: # For type annotation - from typing import Type # for python3.5.1 from sphinx.application import Sphinx diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py index 699738888..83eb282ac 100644 --- a/sphinx/util/docfields.py +++ b/sphinx/util/docfields.py @@ -10,7 +10,7 @@ """ import warnings -from typing import Any, Dict, List, Tuple, Union +from typing import Any, Dict, List, Tuple, Type, Union from typing import cast from docutils import nodes @@ -22,7 +22,6 @@ from sphinx.util.typing import TextlikeNode if False: # For type annotation - from typing import Type # for python3.5.1 from sphinx.environment import BuildEnvironment from sphinx.directive import ObjectDescription diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py index 3b7b60201..32b90a332 100644 --- a/sphinx/util/docutils.py +++ b/sphinx/util/docutils.py @@ -15,7 +15,7 @@ from copy import copy from distutils.version import LooseVersion from os import path from types import ModuleType -from typing import Any, Callable, Dict, Generator, IO, List, Optional, Set, Tuple +from typing import Any, Callable, Dict, Generator, IO, List, Optional, Set, Tuple, Type from typing import cast import docutils @@ -36,7 +36,6 @@ report_re = re.compile('^(.+?:(?:\\d+)?): \\((DEBUG|INFO|WARNING|ERROR|SEVERE)/( if False: # For type annotation - from typing import Type # for python3.5.1 from sphinx.builders import Builder from sphinx.config import Config from sphinx.environment import BuildEnvironment diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 281ef4493..fb5e96d5f 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -24,7 +24,7 @@ from typing import Any, Callable, Mapping, List, Tuple from typing import cast from sphinx.deprecation import RemovedInSphinx40Warning, RemovedInSphinx50Warning -from sphinx.pycode.ast import ast # for py35-37 +from sphinx.pycode.ast import ast # for py36-37 from sphinx.pycode.ast import unparse as ast_unparse from sphinx.util import logging from sphinx.util.typing import stringify as stringify_annotation diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py index fb2ec2900..266e2b0a0 100644 --- a/sphinx/util/logging.py +++ b/sphinx/util/logging.py @@ -12,7 +12,7 @@ import logging import logging.handlers from collections import defaultdict from contextlib import contextmanager -from typing import Any, Dict, Generator, IO, List, Tuple, Union +from typing import Any, Dict, Generator, IO, List, Tuple, Type, Union from docutils import nodes from docutils.nodes import Node @@ -23,7 +23,6 @@ from sphinx.util.console import colorize if False: # For type annotation - from typing import Type # for python3.5.1 from sphinx.application import Sphinx diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index fa51bec6a..6a3c6591d 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -10,7 +10,7 @@ import re import warnings -from typing import Any, Callable, Iterable, List, Set, Tuple +from typing import Any, Callable, Iterable, List, Set, Tuple, Type from typing import cast from docutils import nodes @@ -26,7 +26,6 @@ from sphinx.util import logging if False: # For type annotation - from typing import Type # for python3.5.1 from sphinx.builders import Builder from sphinx.environment import BuildEnvironment from sphinx.utils.tags import Tags diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index e44211cf9..c070abe34 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -18,7 +18,7 @@ import sys import warnings from io import StringIO from os import path -from typing import Any, Generator, Iterator, List, Tuple +from typing import Any, Generator, Iterator, List, Tuple, Type from sphinx.deprecation import RemovedInSphinx40Warning @@ -28,10 +28,6 @@ try: except ImportError: Path = None # type: ignore -if False: - # For type annotation - from typing import Type # for python3.5.1 - # Errnos that we need. EEXIST = getattr(errno, 'EEXIST', 0) # RemovedInSphinx40Warning ENOENT = getattr(errno, 'ENOENT', 0) # RemovedInSphinx40Warning diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index eb38d232c..c2e683eee 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -101,7 +101,7 @@ def _stringify_py37(annotation: Any) -> str: def _stringify_py36(annotation: Any) -> str: - """stringify() for py35 and py36.""" + """stringify() for py36.""" module = getattr(annotation, '__module__', None) if module == 'typing': if getattr(annotation, '_name', None): @@ -129,33 +129,18 @@ def _stringify_py36(annotation: Any) -> str: return qualname elif isinstance(annotation, typing.GenericMeta): params = None - if hasattr(annotation, '__args__'): - # for Python 3.5.2+ - if annotation.__args__ is None or len(annotation.__args__) <= 2: # type: ignore # NOQA - params = annotation.__args__ # type: ignore - else: # typing.Callable - args = ', '.join(stringify(arg) for arg - in annotation.__args__[:-1]) # type: ignore - result = stringify(annotation.__args__[-1]) # type: ignore - return '%s[[%s], %s]' % (qualname, args, result) - elif hasattr(annotation, '__parameters__'): - # for Python 3.5.0 and 3.5.1 - params = annotation.__parameters__ # type: ignore + if annotation.__args__ is None or len(annotation.__args__) <= 2: # type: ignore # NOQA + params = annotation.__args__ # type: ignore + else: # typing.Callable + args = ', '.join(stringify(arg) for arg + in annotation.__args__[:-1]) # type: ignore + result = stringify(annotation.__args__[-1]) # type: ignore + return '%s[[%s], %s]' % (qualname, args, result) if params is not None: param_str = ', '.join(stringify(p) for p in params) return '%s[%s]' % (qualname, param_str) - elif (hasattr(typing, 'UnionMeta') and - isinstance(annotation, typing.UnionMeta) and # type: ignore - hasattr(annotation, '__union_params__')): # for Python 3.5 - params = annotation.__union_params__ - if params is not None: - if len(params) == 2 and params[1] is NoneType: # type: ignore - return 'Optional[%s]' % stringify(params[0]) - else: - param_str = ', '.join(stringify(p) for p in params) - return '%s[%s]' % (qualname, param_str) elif (hasattr(annotation, '__origin__') and - annotation.__origin__ is typing.Union): # for Python 3.5.2+ + annotation.__origin__ is typing.Union): params = annotation.__args__ if params is not None: if len(params) == 2 and params[1] is NoneType: # type: ignore @@ -163,30 +148,5 @@ def _stringify_py36(annotation: Any) -> str: else: param_str = ', '.join(stringify(p) for p in params) return 'Union[%s]' % param_str - elif (isinstance(annotation, typing.CallableMeta) and # type: ignore - getattr(annotation, '__args__', None) is not None and - hasattr(annotation, '__result__')): # for Python 3.5 - # Skipped in the case of plain typing.Callable - args = annotation.__args__ - if args is None: - return qualname - elif args is Ellipsis: - args_str = '...' - else: - formatted_args = (stringify(a) for a in args) - args_str = '[%s]' % ', '.join(formatted_args) - return '%s[%s, %s]' % (qualname, - args_str, - stringify(annotation.__result__)) - elif (isinstance(annotation, typing.TupleMeta) and # type: ignore - hasattr(annotation, '__tuple_params__') and - hasattr(annotation, '__tuple_use_ellipsis__')): # for Python 3.5 - params = annotation.__tuple_params__ - if params is not None: - param_strings = [stringify(p) for p in params] - if annotation.__tuple_use_ellipsis__: - param_strings.append('...') - return '%s[%s]' % (qualname, - ', '.join(param_strings)) return qualname diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index 5da11840d..bb8fb66a7 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -772,4 +772,3 @@ class HTML5Translator(SphinxTranslator, BaseTranslator): for id in node['ids'][1:]: self.body.append('<span id="%s"></span>' % id) node['ids'].remove(id) - |