diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-02-07 19:29:24 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-02-09 22:49:01 +0900 |
commit | d25c3ad2419aa01ab0b64898ebe71bb7139928cb (patch) | |
tree | 8fd4655ec193f4bde52f75828803769d491ba734 | |
parent | 84458da82889e28fc44988601a79c0c562e0e994 (diff) | |
download | sphinx-git-d25c3ad2419aa01ab0b64898ebe71bb7139928cb.tar.gz |
Update type annotations
-rw-r--r-- | sphinx/application.py | 3 | ||||
-rw-r--r-- | sphinx/deprecation.py | 2 | ||||
-rw-r--r-- | sphinx/locale/__init__.py | 8 | ||||
-rw-r--r-- | sphinx/pycode/ast.py | 4 | ||||
-rw-r--r-- | sphinx/util/i18n.py | 6 | ||||
-rw-r--r-- | sphinx/util/images.py | 4 | ||||
-rw-r--r-- | sphinx/util/logging.py | 6 | ||||
-rw-r--r-- | sphinx/util/matching.py | 6 | ||||
-rw-r--r-- | sphinx/util/tags.py | 2 |
9 files changed, 24 insertions, 17 deletions
diff --git a/sphinx/application.py b/sphinx/application.py index c4fc9c212..b5cc44268 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -130,6 +130,9 @@ class Sphinx: :ivar outdir: Directory for storing build documents. """ + warningiserror: bool + _warncount: int + def __init__(self, srcdir: str, confdir: Optional[str], outdir: str, doctreedir: str, buildername: str, confoverrides: Dict = None, status: IO = sys.stdout, warning: IO = sys.stderr, diff --git a/sphinx/deprecation.py b/sphinx/deprecation.py index 1d602fa82..aeefcc61f 100644 --- a/sphinx/deprecation.py +++ b/sphinx/deprecation.py @@ -30,7 +30,7 @@ RemovedInNextVersionWarning = RemovedInSphinx50Warning def deprecated_alias(modname: str, objects: Dict[str, object], - warning: "Type[Warning]", names: Dict[str, str] = None) -> None: + warning: "Type[Warning]", names: Dict[str, str] = {}) -> None: module = import_module(modname) sys.modules[modname] = _ModuleWrapper( # type: ignore module, modname, objects, warning, names) diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py index bedd9e1cb..28dda2e1a 100644 --- a/sphinx/locale/__init__.py +++ b/sphinx/locale/__init__.py @@ -106,7 +106,7 @@ class _TranslationProxy(UserString): translators = defaultdict(NullTranslations) # type: Dict[Tuple[str, str], NullTranslations] -def init(locale_dirs: List[Optional[str]], language: str, +def init(locale_dirs: List[Optional[str]], language: Optional[str], catalog: str = 'sphinx', namespace: str = 'general') -> Tuple[NullTranslations, bool]: """Look for message catalogs in `locale_dirs` and *ensure* that there is at least a NullTranslations catalog set in `translators`. If called multiple @@ -123,9 +123,11 @@ def init(locale_dirs: List[Optional[str]], language: str, if language and '_' in language: # for language having country code (like "de_AT") - languages = [language, language.split('_')[0]] - else: + languages = [language, language.split('_')[0]] # type: Optional[List[str]] + elif language: languages = [language] + else: + languages = None # loading for dir_ in locale_dirs: diff --git a/sphinx/pycode/ast.py b/sphinx/pycode/ast.py index b9fbfc83d..e4e773b25 100644 --- a/sphinx/pycode/ast.py +++ b/sphinx/pycode/ast.py @@ -108,7 +108,7 @@ class _UnparseVisitor(ast.NodeVisitor): return name def visit_arguments(self, node: ast.arguments) -> str: - defaults = list(node.defaults) + defaults = list(node.defaults) # type: List[Optional[ast.expr]] positionals = len(node.args) posonlyargs = 0 if hasattr(node, "posonlyargs"): # for py38+ @@ -117,7 +117,7 @@ class _UnparseVisitor(ast.NodeVisitor): for _ in range(len(defaults), positionals): defaults.insert(0, None) - kw_defaults = list(node.kw_defaults) + kw_defaults = list(node.kw_defaults) # type: List[Optional[ast.expr]] for _ in range(len(kw_defaults), len(node.kwonlyargs)): kw_defaults.insert(0, None) diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py index 3a5aca58e..d647d6d05 100644 --- a/sphinx/util/i18n.py +++ b/sphinx/util/i18n.py @@ -12,7 +12,7 @@ import os import re from datetime import datetime, timezone from os import path -from typing import TYPE_CHECKING, Callable, Generator, List, NamedTuple, Tuple, Union +from typing import TYPE_CHECKING, Callable, Generator, List, NamedTuple, Optional, Tuple, Union import babel.dates from babel.messages.mofile import write_mo @@ -170,7 +170,7 @@ date_format_mappings = { date_format_re = re.compile('(%s)' % '|'.join(date_format_mappings)) -def babel_format_date(date: datetime, format: str, locale: str, +def babel_format_date(date: datetime, format: str, locale: Optional[str], formatter: Callable = babel.dates.format_date) -> str: if locale is None: locale = 'en' @@ -191,7 +191,7 @@ def babel_format_date(date: datetime, format: str, locale: str, return format -def format_date(format: str, date: datetime = None, language: str = None) -> str: +def format_date(format: str, date: datetime = None, language: Optional[str] = None) -> str: if date is None: # If time is not specified, try to use $SOURCE_DATE_EPOCH variable # See https://wiki.debian.org/ReproducibleBuilds/TimestampsProposal diff --git a/sphinx/util/images.py b/sphinx/util/images.py index 8c32e3414..a2a31f55b 100644 --- a/sphinx/util/images.py +++ b/sphinx/util/images.py @@ -12,7 +12,7 @@ import base64 import imghdr from collections import OrderedDict from os import path -from typing import IO, NamedTuple, Optional, Tuple +from typing import IO, BinaryIO, NamedTuple, Optional, Tuple import imagesize @@ -103,7 +103,7 @@ def parse_data_uri(uri: str) -> Optional[DataURI]: return DataURI(mimetype, charset, image_data) -def test_svg(h: bytes, f: IO) -> Optional[str]: +def test_svg(h: bytes, f: Optional[BinaryIO]) -> Optional[str]: """An additional imghdr library helper; test the header is SVG's or not.""" try: if '<svg' in h.decode().lower(): diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py index 1c480e017..dd04b3f23 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 IO, TYPE_CHECKING, Any, Dict, Generator, List, Tuple, Type, Union +from typing import IO, TYPE_CHECKING, Any, Dict, Generator, List, Optional, Tuple, Type, Union from docutils import nodes from docutils.nodes import Node @@ -353,6 +353,8 @@ def is_suppressed_warning(type: str, subtype: str, suppress_warnings: List[str]) if type is None: return False + subtarget: Optional[str] + for warning_type in suppress_warnings: if '.' in warning_type: target, subtarget = warning_type.split('.', 1) @@ -506,7 +508,7 @@ class WarningLogRecordTranslator(SphinxLogRecordTranslator): LogRecordClass = SphinxWarningLogRecord -def get_node_location(node: Node) -> str: +def get_node_location(node: Node) -> Optional[str]: (source, line) = get_source_line(node) if source and line: return "%s:%s" % (source, line) diff --git a/sphinx/util/matching.py b/sphinx/util/matching.py index d33ae0333..2ed804677 100644 --- a/sphinx/util/matching.py +++ b/sphinx/util/matching.py @@ -9,7 +9,7 @@ """ import re -from typing import Callable, Dict, Iterable, List, Match, Pattern +from typing import Callable, Dict, Iterable, List, Match, Optional, Pattern from sphinx.util.osutil import canon_path @@ -60,7 +60,7 @@ def _translate_pattern(pat: str) -> str: return res + '$' -def compile_matchers(patterns: List[str]) -> List[Callable[[str], Match[str]]]: +def compile_matchers(patterns: List[str]) -> List[Callable[[str], Optional[Match[str]]]]: return [re.compile(_translate_pattern(pat)).match for pat in patterns] @@ -89,7 +89,7 @@ DOTFILES = Matcher(['**/.*']) _pat_cache = {} # type: Dict[str, Pattern] -def patmatch(name: str, pat: str) -> Match[str]: +def patmatch(name: str, pat: str) -> Optional[Match[str]]: """Return if name matches pat. Adapted from fnmatch module.""" if pat not in _pat_cache: _pat_cache[pat] = re.compile(_translate_pattern(pat)) diff --git a/sphinx/util/tags.py b/sphinx/util/tags.py index c50231220..cf3d53400 100644 --- a/sphinx/util/tags.py +++ b/sphinx/util/tags.py @@ -22,7 +22,7 @@ class BooleanParser(Parser): """ def parse_compare(self) -> Node: - node = None # type: Node + node: Node token = self.stream.current if token.type == 'name': if token.value in ('true', 'false', 'True', 'False'): |