diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-12-16 00:32:10 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-16 00:32:10 +0900 |
commit | c70e65fc6cd04d02df4f7911025f534dbd27cc20 (patch) | |
tree | 1e8614ac5516dace99ef1df4d203081662c7c2d6 /sphinx/domains/python.py | |
parent | d6d4406ce987cc8823d1b3a33be3a418bcd2a59d (diff) | |
parent | 79eec90f36f5a74e24cfd6740126396fd6567e07 (diff) | |
download | sphinx-git-c70e65fc6cd04d02df4f7911025f534dbd27cc20.tar.gz |
Merge branch 'master' into 5770_doctest_refers_highlight_language
Diffstat (limited to 'sphinx/domains/python.py')
-rw-r--r-- | sphinx/domains/python.py | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 8c5c6f999..c0df50979 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -31,7 +31,7 @@ if False: from sphinx.application import Sphinx # NOQA from sphinx.builders import Builder # NOQA from sphinx.environment import BuildEnvironment # NOQA - from sphinx.util.typing import TextlikeNode, unicode # NOQA + from sphinx.util.typing import TextlikeNode # NOQA logger = logging.getLogger(__name__) @@ -54,7 +54,7 @@ pairindextypes = { 'exception': _('exception'), 'statement': _('statement'), 'builtin': _('built-in function'), -} # Dict[unicode, unicode] +} locale.pairindextypes = DeprecatedDict( pairindextypes, @@ -65,7 +65,7 @@ locale.pairindextypes = DeprecatedDict( def _pseudo_parse_arglist(signode, arglist): - # type: (addnodes.desc_signature, unicode) -> None + # type: (addnodes.desc_signature, str) -> None """"Parse" a list of arguments separated by commas. Arguments can have "optional" annotations given by enclosing them in @@ -117,9 +117,9 @@ def _pseudo_parse_arglist(signode, arglist): # when it comes to handling "." and "~" prefixes. class PyXrefMixin: def make_xref(self, - rolename, # type: unicode - domain, # type: unicode - target, # type: unicode + rolename, # type: str + domain, # type: str + target, # type: str innernode=nodes.emphasis, # type: Type[TextlikeNode] contnode=None, # type: nodes.Node env=None, # type: BuildEnvironment @@ -140,9 +140,9 @@ class PyXrefMixin: return result def make_xrefs(self, - rolename, # type: unicode - domain, # type: unicode - target, # type: unicode + rolename, # type: str + domain, # type: str + target, # type: str innernode=nodes.emphasis, # type: Type[TextlikeNode] contnode=None, # type: nodes.Node env=None, # type: BuildEnvironment @@ -171,7 +171,7 @@ class PyXrefMixin: class PyField(PyXrefMixin, Field): def make_xref(self, rolename, domain, target, innernode=nodes.emphasis, contnode=None, env=None): - # type: (unicode, unicode, unicode, Type[TextlikeNode], nodes.Node, BuildEnvironment) -> nodes.Node # NOQA + # type: (str, str, str, Type[TextlikeNode], nodes.Node, BuildEnvironment) -> nodes.Node # NOQA if rolename == 'class' and target == 'None': # None is not a type, so use obj role instead. rolename = 'obj' @@ -187,7 +187,7 @@ class PyGroupedField(PyXrefMixin, GroupedField): class PyTypedField(PyXrefMixin, TypedField): def make_xref(self, rolename, domain, target, innernode=nodes.emphasis, contnode=None, env=None): - # type: (unicode, unicode, unicode, Type[TextlikeNode], nodes.Node, BuildEnvironment) -> nodes.Node # NOQA + # type: (str, str, str, Type[TextlikeNode], nodes.Node, BuildEnvironment) -> nodes.Node # NOQA if rolename == 'class' and target == 'None': # None is not a type, so use obj role instead. rolename = 'obj' @@ -231,7 +231,7 @@ class PyObject(ObjectDescription): allow_nesting = False def get_signature_prefix(self, sig): - # type: (unicode) -> unicode + # type: (str) -> str """May return a prefix to put before the object name in the signature. """ @@ -245,7 +245,7 @@ class PyObject(ObjectDescription): return False def handle_signature(self, sig, signode): - # type: (unicode, addnodes.desc_signature) -> Tuple[unicode, unicode] + # type: (str, addnodes.desc_signature) -> Tuple[str, str] """Transform a Python signature into RST nodes. Return (fully qualified name of the thing, classname if any). @@ -325,12 +325,12 @@ class PyObject(ObjectDescription): return fullname, name_prefix def get_index_text(self, modname, name): - # type: (unicode, unicode) -> unicode + # type: (str, str) -> str """Return the text for the index entry of the object.""" raise NotImplementedError('must be implemented in subclasses') def add_target_and_index(self, name_cls, sig, signode): - # type: (unicode, unicode, addnodes.desc_signature) -> None + # type: (str, str, addnodes.desc_signature) -> None modname = self.options.get( 'module', self.env.ref_context.get('py:module')) fullname = (modname and modname + '.' or '') + name_cls[0] @@ -426,7 +426,7 @@ class PyModulelevel(PyObject): return self.objtype == 'function' def get_index_text(self, modname, name_cls): - # type: (unicode, unicode) -> unicode + # type: (str, str) -> str if self.objtype == 'function': if not modname: return _('%s() (built-in function)') % name_cls[0] @@ -447,11 +447,11 @@ class PyClasslike(PyObject): allow_nesting = True def get_signature_prefix(self, sig): - # type: (unicode) -> unicode + # type: (str) -> str return self.objtype + ' ' def get_index_text(self, modname, name_cls): - # type: (unicode, unicode) -> unicode + # type: (str, str) -> str if self.objtype == 'class': if not modname: return _('%s (built-in class)') % name_cls[0] @@ -472,7 +472,7 @@ class PyClassmember(PyObject): return self.objtype.endswith('method') def get_signature_prefix(self, sig): - # type: (unicode) -> unicode + # type: (str) -> str if self.objtype == 'staticmethod': return 'static ' elif self.objtype == 'classmethod': @@ -480,7 +480,7 @@ class PyClassmember(PyObject): return '' def get_index_text(self, modname, name_cls): - # type: (unicode, unicode) -> unicode + # type: (str, str) -> str name, cls = name_cls add_modules = self.env.config.add_module_names if self.objtype == 'method': @@ -542,7 +542,7 @@ class PyDecoratorMixin: Mixin for decorator directives. """ def handle_signature(self, sig, signode): - # type: (unicode, addnodes.desc_signature) -> Tuple[unicode, unicode] + # type: (str, addnodes.desc_signature) -> Tuple[str, str] ret = super(PyDecoratorMixin, self).handle_signature(sig, signode) # type: ignore signode.insert(0, addnodes.desc_addname('@', '@')) return ret @@ -640,7 +640,7 @@ class PyCurrentModule(SphinxDirective): class PyXRefRole(XRefRole): def process_link(self, env, refnode, has_explicit_title, title, target): - # type: (BuildEnvironment, nodes.Element, bool, unicode, unicode) -> Tuple[unicode, unicode] # NOQA + # type: (BuildEnvironment, nodes.Element, bool, str, str) -> Tuple[str, str] refnode['py:module'] = env.ref_context.get('py:module') refnode['py:class'] = env.ref_context.get('py:class') if not has_explicit_title: @@ -671,10 +671,10 @@ class PythonModuleIndex(Index): shortname = _('modules') def generate(self, docnames=None): - # type: (Iterable[unicode]) -> Tuple[List[Tuple[unicode, List[IndexEntry]]], bool] - content = {} # type: Dict[unicode, List[IndexEntry]] + # type: (Iterable[str]) -> Tuple[List[Tuple[str, List[IndexEntry]]], bool] + content = {} # type: Dict[str, List[IndexEntry]] # list of prefixes to ignore - ignores = None # type: List[unicode] + ignores = None # type: List[str] ignores = self.domain.env.config['modindex_common_prefix'] # type: ignore ignores = sorted(ignores, key=len, reverse=True) # list of all modules, sorted by module name @@ -750,7 +750,7 @@ class PythonDomain(Domain): 'staticmethod': ObjType(_('static method'), 'meth', 'obj'), 'attribute': ObjType(_('attribute'), 'attr', 'obj'), 'module': ObjType(_('module'), 'mod', 'obj'), - } # type: Dict[unicode, ObjType] + } # type: Dict[str, ObjType] directives = { 'function': PyModulelevel, @@ -780,13 +780,13 @@ class PythonDomain(Domain): initial_data = { 'objects': {}, # fullname -> docname, objtype 'modules': {}, # modname -> docname, synopsis, platform, deprecated - } # type: Dict[unicode, Dict[unicode, Tuple[Any]]] + } # type: Dict[str, Dict[str, Tuple[Any]]] indices = [ PythonModuleIndex, ] def clear_doc(self, docname): - # type: (unicode) -> None + # type: (str) -> None for fullname, (fn, _l) in list(self.data['objects'].items()): if fn == docname: del self.data['objects'][fullname] @@ -795,7 +795,7 @@ class PythonDomain(Domain): del self.data['modules'][modname] def merge_domaindata(self, docnames, otherdata): - # type: (List[unicode], Dict) -> None + # type: (List[str], Dict) -> None # XXX check duplicates? for fullname, (fn, objtype) in otherdata['objects'].items(): if fn in docnames: @@ -805,7 +805,7 @@ class PythonDomain(Domain): self.data['modules'][modname] = data def find_obj(self, env, modname, classname, name, type, searchmode=0): - # type: (BuildEnvironment, unicode, unicode, unicode, unicode, int) -> List[Tuple[unicode, Any]] # NOQA + # type: (BuildEnvironment, str, str, str, str, int) -> List[Tuple[str, Any]] """Find a Python object for "name", perhaps using the given module and/or classname. Returns a list of (name, object entry) tuples. """ @@ -817,7 +817,7 @@ class PythonDomain(Domain): return [] objects = self.data['objects'] - matches = [] # type: List[Tuple[unicode, Any]] + matches = [] # type: List[Tuple[str, Any]] newname = None if searchmode == 1: @@ -870,7 +870,7 @@ class PythonDomain(Domain): def resolve_xref(self, env, fromdocname, builder, type, target, node, contnode): - # type: (BuildEnvironment, unicode, Builder, unicode, unicode, addnodes.pending_xref, nodes.Element) -> nodes.Element # NOQA + # type: (BuildEnvironment, str, Builder, str, str, addnodes.pending_xref, nodes.Element) -> nodes.Element # NOQA modname = node.get('py:module') clsname = node.get('py:class') searchmode = node.hasattr('refspecific') and 1 or 0 @@ -891,10 +891,10 @@ class PythonDomain(Domain): def resolve_any_xref(self, env, fromdocname, builder, target, node, contnode): - # type: (BuildEnvironment, unicode, Builder, unicode, addnodes.pending_xref, nodes.Element) -> List[Tuple[unicode, nodes.Element]] # NOQA + # type: (BuildEnvironment, str, Builder, str, addnodes.pending_xref, nodes.Element) -> List[Tuple[str, nodes.Element]] # NOQA modname = node.get('py:module') clsname = node.get('py:class') - results = [] # type: List[Tuple[unicode, nodes.Element]] + results = [] # type: List[Tuple[str, nodes.Element]] # always search in "refspecific" mode with the :any: role matches = self.find_obj(env, modname, clsname, target, None, 1) @@ -910,7 +910,7 @@ class PythonDomain(Domain): return results def _make_module_refnode(self, builder, fromdocname, name, contnode): - # type: (Builder, unicode, unicode, nodes.Node) -> nodes.Element + # type: (Builder, str, str, nodes.Node) -> nodes.Element # get additional info for modules docname, synopsis, platform, deprecated = self.data['modules'][name] title = name @@ -924,7 +924,7 @@ class PythonDomain(Domain): 'module-' + name, contnode, title) def get_objects(self): - # type: () -> Iterator[Tuple[unicode, unicode, unicode, unicode, unicode, int]] + # type: () -> Iterator[Tuple[str, str, str, str, str, int]] for modname, info in self.data['modules'].items(): yield (modname, modname, 'module', info[0], 'module-' + modname, 0) for refname, (docname, type) in self.data['objects'].items(): @@ -932,7 +932,7 @@ class PythonDomain(Domain): yield (refname, refname, type, docname, refname, 1) def get_full_qualified_name(self, node): - # type: (nodes.Element) -> unicode + # type: (nodes.Element) -> str modname = node.get('py:module') clsname = node.get('py:class') target = node.get('reftarget') @@ -943,7 +943,7 @@ class PythonDomain(Domain): def setup(app): - # type: (Sphinx) -> Dict[unicode, Any] + # type: (Sphinx) -> Dict[str, Any] app.add_domain(PythonDomain) return { |