Merge pull request #6234 from tk0miya/refactor_pydomain

Update type annotations for python domain
This commit is contained in:
Takeshi KOMIYA 2019-03-31 22:26:03 +09:00 committed by GitHub
commit 73ad148776
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View File

@ -166,7 +166,7 @@ class ObjectDescription(SphinxDirective):
node['objtype'] = node['desctype'] = self.objtype node['objtype'] = node['desctype'] = self.objtype
node['noindex'] = noindex = ('noindex' in self.options) node['noindex'] = noindex = ('noindex' in self.options)
self.names = [] # type: List[str] self.names = [] # type: List[Any]
signatures = self.get_signatures() signatures = self.get_signatures()
for i, sig in enumerate(signatures): for i, sig in enumerate(signatures):
# add a signature node for each signature in the current unit # add a signature node for each signature in the current unit

View File

@ -317,14 +317,13 @@ class PyObject(ObjectDescription):
return fullname, prefix return fullname, prefix
def get_index_text(self, modname, name): def get_index_text(self, modname, name):
# type: (str, str) -> str # type: (str, Tuple[str, str]) -> str
"""Return the text for the index entry of the object.""" """Return the text for the index entry of the object."""
raise NotImplementedError('must be implemented in subclasses') raise NotImplementedError('must be implemented in subclasses')
def add_target_and_index(self, name_cls, sig, signode): def add_target_and_index(self, name_cls, sig, signode):
# type: (str, str, addnodes.desc_signature) -> None # type: (Tuple[str, str], str, addnodes.desc_signature) -> None
modname = self.options.get( modname = self.options.get('module', self.env.ref_context.get('py:module'))
'module', self.env.ref_context.get('py:module'))
fullname = (modname and modname + '.' or '') + name_cls[0] fullname = (modname and modname + '.' or '') + name_cls[0]
# note target # note target
if fullname not in self.state.document.ids: if fullname not in self.state.document.ids:
@ -418,7 +417,7 @@ class PyModulelevel(PyObject):
return self.objtype == 'function' return self.objtype == 'function'
def get_index_text(self, modname, name_cls): def get_index_text(self, modname, name_cls):
# type: (str, str) -> str # type: (str, Tuple[str, str]) -> str
if self.objtype == 'function': if self.objtype == 'function':
if not modname: if not modname:
return _('%s() (built-in function)') % name_cls[0] return _('%s() (built-in function)') % name_cls[0]
@ -443,7 +442,7 @@ class PyClasslike(PyObject):
return self.objtype + ' ' return self.objtype + ' '
def get_index_text(self, modname, name_cls): def get_index_text(self, modname, name_cls):
# type: (str, str) -> str # type: (str, Tuple[str, str]) -> str
if self.objtype == 'class': if self.objtype == 'class':
if not modname: if not modname:
return _('%s (built-in class)') % name_cls[0] return _('%s (built-in class)') % name_cls[0]
@ -472,7 +471,7 @@ class PyClassmember(PyObject):
return '' return ''
def get_index_text(self, modname, name_cls): def get_index_text(self, modname, name_cls):
# type: (str, str) -> str # type: (str, Tuple[str, str]) -> str
name, cls = name_cls name, cls = name_cls
add_modules = self.env.config.add_module_names add_modules = self.env.config.add_module_names
if self.objtype == 'method': if self.objtype == 'method':