Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-02-07 13:29:24 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-02-09 16:49:01 +0300
commitd25c3ad2419aa01ab0b64898ebe71bb7139928cb (patch)
tree8fd4655ec193f4bde52f75828803769d491ba734 /sphinx/util
parent84458da82889e28fc44988601a79c0c562e0e994 (diff)
Update type annotations
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/i18n.py6
-rw-r--r--sphinx/util/images.py4
-rw-r--r--sphinx/util/logging.py6
-rw-r--r--sphinx/util/matching.py6
-rw-r--r--sphinx/util/tags.py2
5 files changed, 13 insertions, 11 deletions
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'):