From 20b99ee568fd15ca2897f995e9775861ef293544 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sun, 24 May 2020 14:20:56 +0100 Subject: Introduce type annotations This patch introduces type annotations, which can be checked with mypy. The coverage is not very comprehensive for now, but it is a starting point and will be expanded in later patches. --- git-arr | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'git-arr') diff --git a/git-arr b/git-arr index 05ac171..b109f23 100755 --- a/git-arr +++ b/git-arr @@ -9,8 +9,9 @@ import optparse import os import re import sys +from typing import Union -import bottle +import bottle # type: ignore import git import utils @@ -328,10 +329,10 @@ def is_404(e): return e.status_code == 404 -def generate(output, only=None): +def generate(output: str, only=None): """Generate static html to the output directory.""" - def write_to(path, func_or_str, args=(), mtime=None): + def write_to(path: str, func_or_str, args=(), mtime=None): path = output + "/" + path dirname = os.path.dirname(path) @@ -339,7 +340,7 @@ def generate(output, only=None): os.makedirs(dirname) if mtime: - path_mtime = 0 + path_mtime: Union[float, int] = 0 if os.path.exists(path): path_mtime = os.stat(path).st_mtime @@ -380,8 +381,8 @@ def generate(output, only=None): print(from_path, "->", to_path) os.symlink(to_path, from_path) - def write_tree(r, bn, mtime): - t = r.tree(bn) + def write_tree(r: git.Repo, bn: str, mtime): + t: git.Tree = r.tree(bn) write_to("r/%s/b/%s/t/index.html" % (r.name, bn), tree, (r, bn), mtime) -- cgit v1.2.3