diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-03-13 16:30:59 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-03-13 16:37:50 +0900 |
commit | aeb9e42d2be2b697879120b18a6380edf934e80b (patch) | |
tree | a60d542a501b15daa8bfdad2cf12b05e6be31379 | |
parent | c817c206265f545529b5fabe43fdf162bbc9bea2 (diff) | |
download | sphinx-git-aeb9e42d2be2b697879120b18a6380edf934e80b.tar.gz |
refactor: Use PEP-526 based variable annotation (sphinx.builders)
-rw-r--r-- | sphinx/builders/__init__.py | 21 | ||||
-rw-r--r-- | sphinx/builders/_epub_base.py | 16 | ||||
-rw-r--r-- | sphinx/builders/changes.py | 6 | ||||
-rw-r--r-- | sphinx/builders/epub3.py | 6 | ||||
-rw-r--r-- | sphinx/builders/gettext.py | 13 | ||||
-rw-r--r-- | sphinx/builders/html/__init__.py | 39 | ||||
-rw-r--r-- | sphinx/builders/latex/__init__.py | 16 | ||||
-rw-r--r-- | sphinx/builders/latex/constants.py | 8 | ||||
-rw-r--r-- | sphinx/builders/latex/theming.py | 2 | ||||
-rw-r--r-- | sphinx/builders/latex/transforms.py | 20 | ||||
-rw-r--r-- | sphinx/builders/linkcheck.py | 30 | ||||
-rw-r--r-- | sphinx/builders/manpage.py | 8 | ||||
-rw-r--r-- | sphinx/builders/singlehtml.py | 4 | ||||
-rw-r--r-- | sphinx/builders/texinfo.py | 3 | ||||
-rw-r--r-- | sphinx/builders/text.py | 4 | ||||
-rw-r--r-- | sphinx/builders/xml.py | 2 |
16 files changed, 98 insertions, 100 deletions
diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index c4ac432e4..5128b016d 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -63,7 +63,7 @@ class Builder: #: default translator class for the builder. This can be overridden by #: :py:meth:`app.set_translator()`. - default_translator_class = None # type: Type[nodes.NodeVisitor] + default_translator_class: Type[nodes.NodeVisitor] = None # doctree versioning method versioning_method = 'none' versioning_compare = False @@ -74,7 +74,7 @@ class Builder: #: The list of MIME types of image formats supported by the builder. #: Image files are searched in the order in which they appear here. - supported_image_types = [] # type: List[str] + supported_image_types: List[str] = [] #: The builder supports remote images or not. supported_remote_images = False #: The builder supports data URIs or not. @@ -87,18 +87,18 @@ class Builder: self.doctreedir = app.doctreedir ensuredir(self.doctreedir) - self.app = app # type: Sphinx - self.env = None # type: BuildEnvironment - self.events = app.events # type: EventManager - self.config = app.config # type: Config - self.tags = app.tags # type: Tags + self.app: Sphinx = app + self.env: BuildEnvironment = None + self.events: EventManager = app.events + self.config: Config = app.config + self.tags: Tags = app.tags self.tags.add(self.format) self.tags.add(self.name) self.tags.add("format_%s" % self.format) self.tags.add("builder_%s" % self.name) # images that need to be copied over (source -> dest) - self.images = {} # type: Dict[str, str] + self.images: Dict[str, str] = {} # basename of images directory self.imagedir = "" # relative path to image directory from current docname (used at writing docs) @@ -106,7 +106,7 @@ class Builder: # these get set later self.parallel_ok = False - self.finish_tasks = None # type: Any + self.finish_tasks: Any = None def set_environment(self, env: BuildEnvironment) -> None: """Store BuildEnvironment object.""" @@ -261,8 +261,7 @@ class Builder: # relative to the source directory and without source_suffix. dirlen = len(self.srcdir) + 1 to_write = [] - suffixes = None # type: Tuple[str] - suffixes = tuple(self.config.source_suffix) # type: ignore + suffixes: Tuple[str] = tuple(self.config.source_suffix) # type: ignore for filename in filenames: filename = path.normpath(path.abspath(filename)) if not filename.startswith(self.srcdir): diff --git a/sphinx/builders/_epub_base.py b/sphinx/builders/_epub_base.py index 3b19bb8d0..65fb1ff9a 100644 --- a/sphinx/builders/_epub_base.py +++ b/sphinx/builders/_epub_base.py @@ -165,9 +165,9 @@ class EpubBuilder(StandaloneHTMLBuilder): self.link_suffix = '.xhtml' self.playorder = 0 self.tocid = 0 - self.id_cache = {} # type: Dict[str, str] + self.id_cache: Dict[str, str] = {} self.use_index = self.get_builder_config('use_index', 'epub') - self.refnodes = [] # type: List[Dict[str, Any]] + self.refnodes: List[Dict[str, Any]] = [] def create_build_info(self) -> BuildInfo: return BuildInfo(self.config, self.tags, ['html', 'epub']) @@ -209,7 +209,7 @@ class EpubBuilder(StandaloneHTMLBuilder): return result def check_refnodes(self, nodes: List[Dict[str, Any]]) -> None: - appeared = set() # type: Set[str] + appeared: Set[str] = set() for node in nodes: if node['refuri'] in appeared: logger.warning( @@ -288,7 +288,7 @@ class EpubBuilder(StandaloneHTMLBuilder): for target in tree.traverse(nodes.target): update_node_id(target) - next_node = target.next_node(ascend=True) # type: Node + next_node: Node = target.next_node(ascend=True) if isinstance(next_node, nodes.Element): update_node_id(next_node) @@ -482,7 +482,7 @@ class EpubBuilder(StandaloneHTMLBuilder): """Create a dictionary with all metadata for the content.opf file properly escaped. """ - metadata = {} # type: Dict[str, Any] + metadata: Dict[str, Any] = {} metadata['title'] = html.escape(self.config.epub_title) metadata['author'] = html.escape(self.config.epub_author) metadata['uid'] = html.escape(self.config.epub_uid) @@ -508,7 +508,7 @@ class EpubBuilder(StandaloneHTMLBuilder): if not self.outdir.endswith(os.sep): self.outdir += os.sep olen = len(self.outdir) - self.files = [] # type: List[str] + self.files: List[str] = [] self.ignored_files = ['.buildinfo', 'mimetype', 'content.opf', 'toc.ncx', 'META-INF/container.xml', 'Thumbs.db', 'ehthumbs.db', '.DS_Store', @@ -623,7 +623,7 @@ class EpubBuilder(StandaloneHTMLBuilder): Subelements of a node are nested inside the navpoint. For nested nodes the parent node is reinserted in the subnav. """ - navstack = [] # type: List[NavPoint] + navstack: List[NavPoint] = [] navstack.append(NavPoint('dummy', 0, '', '', [])) level = 0 lastnode = None @@ -665,7 +665,7 @@ class EpubBuilder(StandaloneHTMLBuilder): """Create a dictionary with all metadata for the toc.ncx file properly escaped. """ - metadata = {} # type: Dict[str, Any] + metadata: Dict[str, Any] = {} metadata['uid'] = self.config.epub_uid metadata['title'] = html.escape(self.config.epub_title) metadata['level'] = level diff --git a/sphinx/builders/changes.py b/sphinx/builders/changes.py index 87dd03fb8..5e51499f9 100644 --- a/sphinx/builders/changes.py +++ b/sphinx/builders/changes.py @@ -51,9 +51,9 @@ class ChangesBuilder(Builder): def write(self, *ignored: Any) -> None: version = self.config.version domain = cast(ChangeSetDomain, self.env.get_domain('changeset')) - libchanges = {} # type: Dict[str, List[Tuple[str, str, int]]] - apichanges = [] # type: List[Tuple[str, str, int]] - otherchanges = {} # type: Dict[Tuple[str, str], List[Tuple[str, str, int]]] + libchanges: Dict[str, List[Tuple[str, str, int]]] = {} + apichanges: List[Tuple[str, str, int]] = [] + otherchanges: Dict[Tuple[str, str], List[Tuple[str, str, int]]] = {} changesets = domain.get_changesets_for(version) if not changesets: diff --git a/sphinx/builders/epub3.py b/sphinx/builders/epub3.py index 623ee45a4..be69e87ef 100644 --- a/sphinx/builders/epub3.py +++ b/sphinx/builders/epub3.py @@ -118,7 +118,7 @@ class Epub3Builder(_epub_base.EpubBuilder): The difference from build_navpoints method is templates which are used when generating navigation documents. """ - navstack = [] # type: List[NavPoint] + navstack: List[NavPoint] = [] navstack.append(NavPoint('', '', [])) level = 0 for node in navnodes: @@ -154,7 +154,7 @@ class Epub3Builder(_epub_base.EpubBuilder): """Create a dictionary with all metadata for the nav.xhtml file properly escaped. """ - metadata = {} # type: Dict + metadata: Dict = {} metadata['lang'] = html.escape(self.config.epub_language) metadata['toc_locale'] = html.escape(self.guide_titles['toc']) metadata['navlist'] = navlist @@ -223,7 +223,7 @@ def validate_config_values(app: Sphinx) -> None: def convert_epub_css_files(app: Sphinx, config: Config) -> None: """This converts string styled epub_css_files to tuple styled one.""" - epub_css_files = [] # type: List[Tuple[str, Dict]] + epub_css_files: List[Tuple[str, Dict]] = [] for entry in config.epub_css_files: if isinstance(entry, str): epub_css_files.append((entry, {})) diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index 78ae06b74..be178ca24 100644 --- a/sphinx/builders/gettext.py +++ b/sphinx/builders/gettext.py @@ -48,10 +48,10 @@ class Catalog: """Catalog of translatable messages.""" def __init__(self) -> None: - self.messages = [] # type: List[str] - # retain insertion order, a la OrderedDict - self.metadata = OrderedDict() # type: Dict[str, List[Tuple[str, int, str]]] - # msgid -> file, line, uid + self.messages: List[str] = [] # retain insertion order, a la OrderedDict + + # msgid -> file, line, uid + self.metadata: Dict[str, List[Tuple[str, int, str]]] = OrderedDict() def add(self, msg: str, origin: Union[Element, "MsgOrigin"]) -> None: if not hasattr(origin, 'uid'): @@ -121,8 +121,7 @@ class I18nBuilder(Builder): """ name = 'i18n' versioning_method = 'text' - versioning_compare = None # type: bool - # be set by `gettext_uuid` + versioning_compare: bool = None # be set by `gettext_uuid` use_message_catalog = False def init(self) -> None: @@ -130,7 +129,7 @@ class I18nBuilder(Builder): self.env.set_versioning_method(self.versioning_method, self.env.config.gettext_uuid) self.tags = I18nTags() - self.catalogs = defaultdict(Catalog) # type: DefaultDict[str, Catalog] + self.catalogs: DefaultDict[str, Catalog] = defaultdict(Catalog) def get_target_uri(self, docname: str, typ: str = None) -> str: return '' diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index 115f73538..a62e46b43 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -82,9 +82,9 @@ class Stylesheet(str): its filename (str). """ - attributes = None # type: Dict[str, str] - filename = None # type: str - priority = None # type: int + attributes: Dict[str, str] = None + filename: str = None + priority: int = None def __new__(cls, filename: str, *args: str, priority: int = 500, **attributes: Any ) -> "Stylesheet": @@ -108,9 +108,9 @@ class JavaScript(str): its filename (str). """ - attributes = None # type: Dict[str, str] - filename = None # type: str - priority = None # type: int + attributes: Dict[str, str] = None + filename: str = None + priority: int = None def __new__(cls, filename: str, priority: int = 500, **attributes: str) -> "JavaScript": self = str.__new__(cls, filename) @@ -179,7 +179,7 @@ class StandaloneHTMLBuilder(Builder): allow_parallel = True out_suffix = '.html' link_suffix = '.html' # defaults to matching out_suffix - indexer_format = js_index # type: Any + indexer_format: Any = js_index indexer_dumps_unicode = True # create links to original images from images [True/False] html_scaled_image_link = True @@ -195,26 +195,26 @@ class StandaloneHTMLBuilder(Builder): use_index = False download_support = True # enable download role - imgpath = None # type: str - domain_indices = [] # type: List[Tuple[str, Type[Index], List[Tuple[str, List[IndexEntry]]], bool]] # NOQA + imgpath: str = None + domain_indices: List[Tuple[str, Type[Index], List[Tuple[str, List[IndexEntry]]], bool]] = [] # NOQA def __init__(self, app: Sphinx) -> None: super().__init__(app) # CSS files - self.css_files = [] # type: List[Dict[str, str]] + self.css_files: List[Dict[str, str]] = [] # JS files - self.script_files = [] # type: List[JavaScript] + self.script_files: List[JavaScript] = [] def init(self) -> None: self.build_info = self.create_build_info() # basename of images directory self.imagedir = '_images' # section numbers for headings in the currently visited document - self.secnumbers = {} # type: Dict[str, Tuple[int, ...]] + self.secnumbers: Dict[str, Tuple[int, ...]] = {} # currently written docname - self.current_docname = None # type: str + self.current_docname: str = None self.init_templates() self.init_highlighter() @@ -436,10 +436,10 @@ class StandaloneHTMLBuilder(Builder): self.load_indexer(docnames) self.docwriter = HTMLWriter(self) - self.docsettings = OptionParser( + self.docsettings: Any = OptionParser( defaults=self.env.settings, components=(self.docwriter,), - read_config_files=True).get_default_values() # type: Any + read_config_files=True).get_default_values() self.docsettings.compact_lists = bool(self.config.html_compact_lists) # determine the additional indices to include @@ -448,8 +448,7 @@ class StandaloneHTMLBuilder(Builder): indices_config = self.config.html_domain_indices if indices_config: for domain_name in sorted(self.env.domains): - domain = None # type: Domain - domain = self.env.domains[domain_name] + domain: Domain = self.env.domains[domain_name] for indexcls in domain.indices: indexname = '%s-%s' % (domain.name, indexcls.name) if isinstance(indices_config, list): @@ -474,7 +473,7 @@ class StandaloneHTMLBuilder(Builder): self.relations = self.env.collect_relations() - rellinks = [] # type: List[Tuple[str, str, str, str]] + rellinks: List[Tuple[str, str, str, str]] = [] if self.use_index: rellinks.append(('genindex', _('General Index'), 'I', _('index'))) for indexname, indexcls, content, collapse in self.domain_indices: @@ -1109,7 +1108,7 @@ class StandaloneHTMLBuilder(Builder): def convert_html_css_files(app: Sphinx, config: Config) -> None: """This converts string styled html_css_files to tuple styled one.""" - html_css_files = [] # type: List[Tuple[str, Dict]] + html_css_files: List[Tuple[str, Dict]] = [] for entry in config.html_css_files: if isinstance(entry, str): html_css_files.append((entry, {})) @@ -1126,7 +1125,7 @@ def convert_html_css_files(app: Sphinx, config: Config) -> None: def convert_html_js_files(app: Sphinx, config: Config) -> None: """This converts string styled html_js_files to tuple styled one.""" - html_js_files = [] # type: List[Tuple[str, Dict]] + html_js_files: List[Tuple[str, Dict]] = [] for entry in config.html_js_files: if isinstance(entry, str): html_js_files.append((entry, {})) diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py index e1945422e..a37a35e61 100644 --- a/sphinx/builders/latex/__init__.py +++ b/sphinx/builders/latex/__init__.py @@ -122,10 +122,10 @@ class LaTeXBuilder(Builder): default_translator_class = LaTeXTranslator def init(self) -> None: - self.babel = None # type: ExtBabel - self.context = {} # type: Dict[str, Any] - self.docnames = [] # type: Iterable[str] - self.document_data = [] # type: List[Tuple[str, str, str, str, str, bool]] + self.babel: ExtBabel = None + self.context: Dict[str, Any] = {} + self.docnames: Iterable[str] = {} + self.document_data: List[Tuple[str, str, str, str, str, bool]] = [] self.themes = ThemeFactory(self.app) texescape.init() @@ -153,7 +153,7 @@ class LaTeXBuilder(Builder): 'will be written')) return # assign subdirs to titles - self.titles = [] # type: List[Tuple[str, str]] + self.titles: List[Tuple[str, str]] = [] for entry in preliminary_document_data: docname = entry[0] if docname not in self.env.all_docs: @@ -262,10 +262,10 @@ class LaTeXBuilder(Builder): def write(self, *ignored: Any) -> None: docwriter = LaTeXWriter(self) - docsettings = OptionParser( + docsettings: Any = OptionParser( defaults=self.env.settings, components=(docwriter,), - read_config_files=True).get_default_values() # type: Any + read_config_files=True).get_default_values() self.init_document_data() self.write_stylesheet() @@ -356,7 +356,7 @@ class LaTeXBuilder(Builder): for pendingnode in largetree.traverse(addnodes.pending_xref): docname = pendingnode['refdocname'] sectname = pendingnode['refsectname'] - newnodes = [nodes.emphasis(sectname, sectname)] # type: List[Node] + newnodes: List[Node] = [nodes.emphasis(sectname, sectname)] for subdir, title in self.titles: if docname.startswith(subdir): newnodes.append(nodes.Text(_(' (in '), _(' (in '))) diff --git a/sphinx/builders/latex/constants.py b/sphinx/builders/latex/constants.py index e929736a7..f5e69225d 100644 --- a/sphinx/builders/latex/constants.py +++ b/sphinx/builders/latex/constants.py @@ -71,7 +71,7 @@ XELATEX_GREEK_DEFAULT_FONTPKG = (XELATEX_DEFAULT_FONTPKG + LUALATEX_DEFAULT_FONTPKG = XELATEX_DEFAULT_FONTPKG -DEFAULT_SETTINGS = { +DEFAULT_SETTINGS: Dict[str, Any] = { 'latex_engine': 'pdflatex', 'papersize': '', 'pointsize': '', @@ -121,9 +121,9 @@ DEFAULT_SETTINGS = { 'figure_align': 'htbp', 'tocdepth': '', 'secnumdepth': '', -} # type: Dict[str, Any] +} -ADDITIONAL_SETTINGS = { +ADDITIONAL_SETTINGS: Dict[Any, Dict[str, Any]] = { 'pdflatex': { 'inputenc': '\\usepackage[utf8]{inputenc}', 'utf8extra': ('\\ifdefined\\DeclareUnicodeCharacter\n' @@ -202,7 +202,7 @@ ADDITIONAL_SETTINGS = { ('xelatex', 'el'): { 'fontpkg': XELATEX_GREEK_DEFAULT_FONTPKG, }, -} # type: Dict[Any, Dict[str, Any]] +} SHORTHANDOFF = r''' diff --git a/sphinx/builders/latex/theming.py b/sphinx/builders/latex/theming.py index 5af79e8a2..d5c53a58b 100644 --- a/sphinx/builders/latex/theming.py +++ b/sphinx/builders/latex/theming.py @@ -106,7 +106,7 @@ class ThemeFactory: """A factory class for LaTeX Themes.""" def __init__(self, app: Sphinx) -> None: - self.themes = {} # type: Dict[str, Theme] + self.themes: Dict[str, Theme] = {} self.theme_paths = [path.join(app.srcdir, p) for p in app.config.latex_theme_path] self.config = app.config self.load_builtin_themes(app.config) diff --git a/sphinx/builders/latex/transforms.py b/sphinx/builders/latex/transforms.py index 0a74eded4..a07393690 100644 --- a/sphinx/builders/latex/transforms.py +++ b/sphinx/builders/latex/transforms.py @@ -33,7 +33,7 @@ class FootnoteDocnameUpdater(SphinxTransform): def apply(self, **kwargs: Any) -> None: matcher = NodeMatcher(*self.TARGET_NODES) - for node in self.document.traverse(matcher): # type: nodes.Element + for node in self.document.traverse(matcher): # type: Element node['docname'] = self.env.docname @@ -65,7 +65,7 @@ class ShowUrlsTransform(SphinxPostTransform): def run(self, **kwargs: Any) -> None: try: # replace id_prefix temporarily - settings = self.document.settings # type: Any + settings: Any = self.document.settings id_prefix = settings.id_prefix settings.id_prefix = 'show_urls' @@ -157,9 +157,9 @@ class FootnoteCollector(nodes.NodeVisitor): """Collect footnotes and footnote references on the document""" def __init__(self, document: nodes.document) -> None: - self.auto_footnotes = [] # type: List[nodes.footnote] - self.used_footnote_numbers = set() # type: Set[str] - self.footnote_refs = [] # type: List[nodes.footnote_reference] + self.auto_footnotes: List[nodes.footnote] = [] + self.used_footnote_numbers: Set[str] = set() + self.footnote_refs: List[nodes.footnote_reference] = [] super().__init__(document) def unknown_visit(self, node: Node) -> None: @@ -358,11 +358,11 @@ class LaTeXFootnoteTransform(SphinxPostTransform): class LaTeXFootnoteVisitor(nodes.NodeVisitor): def __init__(self, document: nodes.document, footnotes: List[nodes.footnote]) -> None: - self.appeared = set() # type: Set[Tuple[str, str]] - self.footnotes = footnotes # type: List[nodes.footnote] - self.pendings = [] # type: List[nodes.footnote] - self.table_footnotes = [] # type: List[nodes.footnote] - self.restricted = None # type: nodes.Element + self.appeared: Set[Tuple[str, str]] = set() + self.footnotes: List[nodes.footnote] = footnotes + self.pendings: List[nodes.footnote] = [] + self.table_footnotes: List[nodes.footnote] = [] + self.restricted: Element = None super().__init__(document) def unknown_visit(self, node: Node) -> None: diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index bd81bcee6..05e12c173 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -9,7 +9,6 @@ """ import json -import queue import re import socket import time @@ -18,6 +17,7 @@ from datetime import datetime, timezone from email.utils import parsedate_to_datetime from html.parser import HTMLParser from os import path +from queue import PriorityQueue, Queue from threading import Thread from typing import (Any, Dict, Generator, List, NamedTuple, Optional, Pattern, Set, Tuple, Union, cast) @@ -120,16 +120,16 @@ class CheckExternalLinksBuilder(DummyBuilder): '%(outdir)s/output.txt') def init(self) -> None: - self.hyperlinks = {} # type: Dict[str, Hyperlink] - self._good = set() # type: Set[str] - self._broken = {} # type: Dict[str, str] - self._redirected = {} # type: Dict[str, Tuple[str, int]] + self.hyperlinks: Dict[str, Hyperlink] = {} + self._good: Set[str] = set() + self._broken: Dict[str, str] = {} + self._redirected: Dict[str, Tuple[str, int]] = {} # set a timeout for non-responding servers socket.setdefaulttimeout(5.0) # create queues and worker threads - self._wqueue = queue.PriorityQueue() # type: queue.PriorityQueue[CheckRequestType] - self._rqueue = queue.Queue() # type: queue.Queue + self._wqueue: PriorityQueue[CheckRequestType] = PriorityQueue() + self._rqueue: Queue = Queue() @property def anchors_ignore(self) -> List[Pattern]: @@ -204,7 +204,7 @@ class CheckExternalLinksBuilder(DummyBuilder): None, None, {}) return worker.limit_rate(response) - def rqueue(self, response: Response) -> queue.Queue: + def rqueue(self, response: Response) -> Queue: warnings.warn( "%s.%s is deprecated." % (self.__class__.__name__, "rqueue"), RemovedInSphinx50Warning, @@ -220,7 +220,7 @@ class CheckExternalLinksBuilder(DummyBuilder): ) return [] - def wqueue(self, response: Response) -> queue.Queue: + def wqueue(self, response: Response) -> Queue: warnings.warn( "%s.%s is deprecated." % (self.__class__.__name__, "wqueue"), RemovedInSphinx50Warning, @@ -313,8 +313,8 @@ class HyperlinkAvailabilityChecker: self.builder = builder self.config = config self.env = env - self.rate_limits = {} # type: Dict[str, RateLimit] - self.workers = [] # type: List[Thread] + self.rate_limits: Dict[str, RateLimit] = {} + self.workers: List[Thread] = [] self.to_ignore = [re.compile(x) for x in self.config.linkcheck_ignore] @@ -322,8 +322,8 @@ class HyperlinkAvailabilityChecker: self.rqueue = builder._rqueue self.wqueue = builder._wqueue else: - self.rqueue = queue.Queue() - self.wqueue = queue.PriorityQueue() + self.rqueue = Queue() + self.wqueue = PriorityQueue() def invoke_threads(self) -> None: for i in range(self.config.linkcheck_workers): @@ -364,8 +364,8 @@ class HyperlinkAvailabilityChecker: class HyperlinkAvailabilityCheckWorker(Thread): """A worker class for checking the availability of hyperlinks.""" - def __init__(self, env: BuildEnvironment, config: Config, rqueue: queue.Queue, - wqueue: queue.Queue, rate_limits: Dict[str, RateLimit], + def __init__(self, env: BuildEnvironment, config: Config, rqueue: Queue, + wqueue: Queue, rate_limits: Dict[str, RateLimit], builder: CheckExternalLinksBuilder = None) -> None: # Warning: builder argument will be removed in the sphinx-5.0. # Don't use it from extensions. diff --git a/sphinx/builders/manpage.py b/sphinx/builders/manpage.py index f994309e1..b993a2df4 100644 --- a/sphinx/builders/manpage.py +++ b/sphinx/builders/manpage.py @@ -38,7 +38,7 @@ class ManualPageBuilder(Builder): epilog = __('The manual pages are in %(outdir)s.') default_translator_class = ManualPageTranslator - supported_image_types = [] # type: List[str] + supported_image_types: List[str] = [] def init(self) -> None: if not self.config.man_pages: @@ -56,10 +56,10 @@ class ManualPageBuilder(Builder): @progress_message(__('writing')) def write(self, *ignored: Any) -> None: docwriter = ManualPageWriter(self) - docsettings = OptionParser( + docsettings: Any = OptionParser( defaults=self.env.settings, components=(docwriter,), - read_config_files=True).get_default_values() # type: Any + read_config_files=True).get_default_values() for info in self.config.man_pages: docname, name, description, authors, section = info @@ -90,7 +90,7 @@ class ManualPageBuilder(Builder): encoding='utf-8') tree = self.env.get_doctree(docname) - docnames = set() # type: Set[str] + docnames: Set[str] = set() largetree = inline_all_toctrees(self, docnames, docname, tree, darkgreen, [docname]) largetree.settings = docsettings diff --git a/sphinx/builders/singlehtml.py b/sphinx/builders/singlehtml.py index 1ef618dd0..03d25965b 100644 --- a/sphinx/builders/singlehtml.py +++ b/sphinx/builders/singlehtml.py @@ -93,7 +93,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder): # # There are related codes in inline_all_toctres() and # HTMLTranslter#add_secnumber(). - new_secnumbers = {} # type: Dict[str, Tuple[int, ...]] + new_secnumbers: Dict[str, Tuple[int, ...]] = {} for docname, secnums in self.env.toc_secnumbers.items(): for id, secnum in secnums.items(): alias = "%s/%s" % (docname, id) @@ -111,7 +111,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder): # # There are related codes in inline_all_toctres() and # HTMLTranslter#add_fignumber(). - new_fignumbers = {} # type: Dict[str, Dict[str, Tuple[int, ...]]] + new_fignumbers: Dict[str, Dict[str, Tuple[int, ...]]] = {} # {'foo': {'figure': {'id2': (2,), 'id1': (1,)}}, 'bar': {'figure': {'id1': (3,)}}} for docname, fignumlist in self.env.toc_fignumbers.items(): for figtype, fignums in fignumlist.items(): diff --git a/sphinx/builders/texinfo.py b/sphinx/builders/texinfo.py index bb2039e61..8bd211f22 100644 --- a/sphinx/builders/texinfo.py +++ b/sphinx/builders/texinfo.py @@ -15,6 +15,7 @@ from typing import Any, Dict, Iterable, List, Tuple, Union from docutils import nodes from docutils.frontend import OptionParser from docutils.io import FileOutput +from docutils.nodes import Node from sphinx import addnodes, package_dir from sphinx.application import Sphinx @@ -154,7 +155,7 @@ class TexinfoBuilder(Builder): for pendingnode in largetree.traverse(addnodes.pending_xref): docname = pendingnode['refdocname'] sectname = pendingnode['refsectname'] - newnodes = [nodes.emphasis(sectname, sectname)] # type: List[nodes.Node] + newnodes: List[Node] = [nodes.emphasis(sectname, sectname)] for subdir, title in self.titles: if docname.startswith(subdir): newnodes.append(nodes.Text(_(' (in '), _(' (in '))) diff --git a/sphinx/builders/text.py b/sphinx/builders/text.py index ae770818c..2ac1b2878 100644 --- a/sphinx/builders/text.py +++ b/sphinx/builders/text.py @@ -33,11 +33,11 @@ class TextBuilder(Builder): allow_parallel = True default_translator_class = TextTranslator - current_docname = None # type: str + current_docname: str = None def init(self) -> None: # section numbers for headings in the currently visited document - self.secnumbers = {} # type: Dict[str, Tuple[int, ...]] + self.secnumbers: Dict[str, Tuple[int, ...]] = {} def get_outdated_docs(self) -> Iterator[str]: for docname in self.env.found_docs: diff --git a/sphinx/builders/xml.py b/sphinx/builders/xml.py index 88dfe83a9..865820c36 100644 --- a/sphinx/builders/xml.py +++ b/sphinx/builders/xml.py @@ -37,7 +37,7 @@ class XMLBuilder(Builder): out_suffix = '.xml' allow_parallel = True - _writer_class = XMLWriter # type: Union[Type[XMLWriter], Type[PseudoXMLWriter]] + _writer_class: Union[Type[XMLWriter], Type[PseudoXMLWriter]] = XMLWriter default_translator_class = XMLTranslator def init(self) -> None: |