Add more type annotations

This commit is contained in:
Kovid Goyal 2021-10-27 10:50:24 +05:30
parent 9c2f96f7eb
commit 6f19fd5912
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 23 additions and 17 deletions

View File

@ -170,7 +170,9 @@ texinfo_documents = [
# GitHub linking inline roles {{{
def num_role(which: str, name: str, rawtext: str, text: str, lineno: int, inliner: Any, options: Any = {}, content: Any = []) -> Tuple[List, List]:
def num_role(
which: str, name: str, rawtext: str, text: str, lineno: int, inliner: Any, options: Any = {}, content: Any = []
) -> Tuple[List[nodes.reference], List[nodes.problematic]]:
' Link to a github issue '
try:
issue_num = int(text)
@ -188,7 +190,9 @@ def num_role(which: str, name: str, rawtext: str, text: str, lineno: int, inline
return [node], []
def commit_role(name: str, rawtext: str, text: str, lineno: int, inliner: Any, options: Any = {}, content: Any = []) -> Tuple[List, List]:
def commit_role(
name: str, rawtext: str, text: str, lineno: int, inliner: Any, options: Any = {}, content: Any = []
) -> Tuple[List[nodes.reference], List[nodes.problematic]]:
' Link to a github commit '
try:
commit_id = subprocess.check_output(
@ -264,7 +268,7 @@ def write_remote_control_protocol_docs() -> None: # {{{
)
field_pat = re.compile(r'\s*([a-zA-Z0-9_+]+)\s*:\s*(.+)')
def format_cmd(p: Callable, name: str, cmd: RemoteCommand) -> None:
def format_cmd(p: Callable[..., None], name: str, cmd: RemoteCommand) -> None:
p(name)
p('-' * 80)
lines = (cmd.__doc__ or '').strip().splitlines()
@ -304,7 +308,7 @@ def write_remote_control_protocol_docs() -> None: # {{{
# config file docs {{{
class ConfLexer(RegexLexer):
class ConfLexer(RegexLexer): # type: ignore
name = 'Conf'
aliases = ['conf']
filenames = ['*.conf']
@ -343,7 +347,7 @@ class ConfLexer(RegexLexer):
}
class SessionLexer(RegexLexer):
class SessionLexer(RegexLexer): # type: ignore
name = 'Session'
aliases = ['session']
filenames = ['*.session']
@ -359,7 +363,9 @@ class SessionLexer(RegexLexer):
}
def link_role(name: str, rawtext: str, text: str, lineno: int, inliner: Any, options: Any = {}, content: Any = []) -> Tuple[List, List]:
def link_role(
name: str, rawtext: str, text: str, lineno: int, inliner: Any, options: Any = {}, content: Any = []
) -> Tuple[List[nodes.reference], List[nodes.problematic]]:
text = text.replace('\n', ' ')
m = re.match(r'(.+)\s+<(.+?)>', text)
if m is None:
@ -376,7 +382,7 @@ def link_role(name: str, rawtext: str, text: str, lineno: int, inliner: Any, opt
def expand_opt_references(conf_name: str, text: str) -> str:
conf_name += '.'
def expand(m: Match) -> str:
def expand(m: Match[str]) -> str:
ref = m.group(1)
if '<' not in ref and '.' not in ref:
full_ref = conf_name + ref

View File

@ -251,7 +251,7 @@ def get_ranges(items: List[int]) -> Generator[Union[int, Tuple[int, int]], None,
yield a, b
def write_case(spec: Union[Tuple, int], p: Callable) -> None:
def write_case(spec: Union[Tuple[int, ...], int], p: Callable[..., None]) -> None:
if isinstance(spec, tuple):
p('\t\tcase 0x{:x} ... 0x{:x}:'.format(*spec))
else:
@ -259,7 +259,7 @@ def write_case(spec: Union[Tuple, int], p: Callable) -> None:
@contextmanager
def create_header(path: str, include_data_types: bool = True) -> Generator[Callable, None, None]:
def create_header(path: str, include_data_types: bool = True) -> Generator[Callable[..., None], None, None]:
with open(path, 'w') as f:
p = partial(print, file=f)
p('// unicode data, built from the unicode standard on:', date.today())
@ -299,7 +299,7 @@ def gen_emoji() -> None:
def category_test(
name: str,
p: Callable,
p: Callable[..., None],
classes: Iterable[str],
comment: str,
use_static: bool = False,
@ -329,7 +329,7 @@ def category_test(
p('\treturn false;\n}\n')
def codepoint_to_mark_map(p: Callable, mark_map: List[int]) -> Dict[int, int]:
def codepoint_to_mark_map(p: Callable[..., None], mark_map: List[int]) -> Dict[int, int]:
p('\tswitch(c) { // {{{')
rmap = {c: m for m, c in enumerate(mark_map)}
for spec in get_ranges(mark_map):
@ -522,7 +522,7 @@ def gen_names() -> None:
def gen_wcwidth() -> None:
seen: Set[int] = set()
def add(p: Callable, comment: str, chars_: Union[Set[int], FrozenSet[int]], ret: int) -> None:
def add(p: Callable[..., None], comment: str, chars_: Union[Set[int], FrozenSet[int]], ret: int) -> None:
chars = chars_ - seen
seen.update(chars)
p(f'\t\t// {comment} ({len(chars)} codepoints)' + ' {{' '{')

View File

@ -4,9 +4,9 @@ from .collect import Segment
def split_with_highlights(
line: str, truncate_points: List[int], fg_highlights: List,
line: str, truncate_points: List[int], fg_highlights: List[Segment],
bg_highlight: Optional[Segment]
) -> List:
) -> List[str]:
pass

View File

@ -209,7 +209,7 @@ def truncate_points(line: str, width: int) -> Generator[int, None, None]:
break
def split_with_highlights(line: str, width: int, highlights: List, bg_highlight: Optional[Segment] = None) -> List:
def split_with_highlights(line: str, width: int, highlights: List[Segment], bg_highlight: Optional[Segment] = None) -> List[str]:
truncate_pts = list(truncate_points(line, width))
return _split_with_highlights(line, truncate_pts, highlights, bg_highlight)
@ -270,7 +270,7 @@ def hunk_title(hunk_num: int, hunk: Hunk, margin_size: int, available_cols: int)
def render_half_line(
line_number: int,
line: str,
highlights: List,
highlights: List[Segment],
ltype: str,
margin_size: int,
available_cols: int,

View File

@ -107,7 +107,7 @@ else:
self._override = RunOnce
def run_once(f: Callable[[], _T]) -> RunOnce[_T]:
def run_once(f: Callable[[], _T]) -> 'RunOnce[_T]':
return RunOnce(f)