diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-03-23 01:44:24 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-03-23 01:44:24 +0900 |
commit | 555a52be82be3578470179f9047ed6abb943057e (patch) | |
tree | c183fe533c22ea67f95df65e0548c6a85b06e016 /sphinx/directives | |
parent | 09a037006c71f26bfde7b8ef1940f0a38e0cef86 (diff) | |
download | sphinx-git-555a52be82be3578470179f9047ed6abb943057e.tar.gz |
refactor: Use PEP-526 based variable annotation (sphinx.directives)
Diffstat (limited to 'sphinx/directives')
-rw-r--r-- | sphinx/directives/__init__.py | 12 | ||||
-rw-r--r-- | sphinx/directives/code.py | 4 | ||||
-rw-r--r-- | sphinx/directives/other.py | 12 | ||||
-rw-r--r-- | sphinx/directives/patches.py | 2 |
4 files changed, 15 insertions, 15 deletions
diff --git a/sphinx/directives/__init__.py b/sphinx/directives/__init__.py index f40144809..e1ccc8be7 100644 --- a/sphinx/directives/__init__.py +++ b/sphinx/directives/__init__.py @@ -63,13 +63,13 @@ class ObjectDescription(SphinxDirective, Generic[T]): } # types of doc fields that this directive handles, see sphinx.util.docfields - doc_field_types = [] # type: List[Field] - domain = None # type: str - objtype = None # type: str - indexnode = None # type: addnodes.index + doc_field_types: List[Field] = [] + domain: str = None + objtype: str = None + indexnode: addnodes.index = None # Warning: this might be removed in future version. Don't touch this from extensions. - _doc_field_type_map = {} # type: Dict[str, Tuple[Field, bool]] + _doc_field_type_map: Dict[str, Tuple[Field, bool]] = {} def get_field_type_map(self) -> Dict[str, Tuple[Field, bool]]: if self._doc_field_type_map == {}: @@ -173,7 +173,7 @@ class ObjectDescription(SphinxDirective, Generic[T]): if self.domain: node['classes'].append(self.domain) - self.names = [] # type: List[T] + self.names: List[T] = [] signatures = self.get_signatures() for i, sig in enumerate(signatures): # add a signature node for each signature in the current unit diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index 04b81cef5..12ab51c58 100644 --- a/sphinx/directives/code.py +++ b/sphinx/directives/code.py @@ -142,7 +142,7 @@ class CodeBlock(SphinxDirective): lines = dedent_lines(lines, self.options['dedent'], location=location) code = '\n'.join(lines) - literal = nodes.literal_block(code, code) # type: Element + literal: Element = nodes.literal_block(code, code) if 'linenos' in self.options or 'lineno-start' in self.options: literal['linenos'] = True literal['classes'] += self.options.get('class', []) @@ -422,7 +422,7 @@ class LiteralInclude(SphinxDirective): reader = LiteralIncludeReader(filename, self.options, self.config) text, lines = reader.read(location=location) - retnode = nodes.literal_block(text, text, source=filename) # type: Element + retnode: Element = nodes.literal_block(text, text, source=filename) retnode['force'] = 'force' in self.options self.set_source_info(retnode) if self.options.get('diff'): # if diff is set, set udiff diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index 1daa3c4a5..e131fe820 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -90,7 +90,7 @@ class TocTree(SphinxDirective): all_docnames = self.env.found_docs.copy() all_docnames.remove(self.env.docname) # remove current document - ret = [] # type: List[Node] + ret: List[Node] = [] excluded = Matcher(self.config.exclude_patterns) for entry in self.content: if not entry: @@ -168,7 +168,7 @@ class Author(SphinxDirective): def run(self) -> List[Node]: if not self.config.show_authors: return [] - para = nodes.paragraph(translatable=False) # type: Element + para: Element = nodes.paragraph(translatable=False) emph = nodes.emphasis() para += emph if self.name == 'sectionauthor': @@ -183,7 +183,7 @@ class Author(SphinxDirective): inodes, messages = self.state.inline_text(self.arguments[0], self.lineno) emph.extend(inodes) - ret = [para] # type: List[Node] + ret: List[Node] = [para] ret += messages return ret @@ -225,11 +225,11 @@ class Centered(SphinxDirective): def run(self) -> List[Node]: if not self.arguments: return [] - subnode = addnodes.centered() # type: Element + subnode: Element = addnodes.centered() inodes, messages = self.state.inline_text(self.arguments[0], self.lineno) subnode.extend(inodes) - ret = [subnode] # type: List[Node] + ret: List[Node] = [subnode] ret += messages return ret @@ -309,7 +309,7 @@ class Only(SphinxDirective): # Same as util.nested_parse_with_titles but try to handle nested # sections which should be raised higher up the doctree. - memo = self.state.memo # type: Any + memo: Any = self.state.memo surrounding_title_styles = memo.title_styles surrounding_section_level = memo.section_level memo.title_styles = [] diff --git a/sphinx/directives/patches.py b/sphinx/directives/patches.py index b4c978474..9a3034dae 100644 --- a/sphinx/directives/patches.py +++ b/sphinx/directives/patches.py @@ -206,7 +206,7 @@ class MathDirective(SphinxDirective): self.add_name(node) self.set_source_info(node) - ret = [node] # type: List[Node] + ret: List[Node] = [node] self.add_target(ret) return ret |