From 8ad62106e06927551da29a0f17517480473082e9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Mar 2020 08:08:46 +0530 Subject: [PATCH] No global typing issues in all code (excluding tests) --- gen-wcwidth.py | 14 ++++++++------ publish.py | 9 +++++---- setup.cfg | 3 +++ setup.py | 7 ++++--- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/gen-wcwidth.py b/gen-wcwidth.py index c7498f7c4..35a7945a3 100755 --- a/gen-wcwidth.py +++ b/gen-wcwidth.py @@ -12,6 +12,7 @@ from functools import partial from html.entities import html5 from itertools import groupby from operator import itemgetter +from typing import DefaultDict, Dict, Set from urllib.request import urlopen os.chdir(os.path.dirname(os.path.abspath(__file__))) @@ -42,10 +43,10 @@ def get_data(fname, folder='UCD'): # Map of class names to set of codepoints in class -class_maps = {} +class_maps: Dict[str, Set[int]] = {} all_symbols = set() name_map = {} -word_search_map = defaultdict(set) +word_search_map: DefaultDict[str, Set[int]] = defaultdict(set) zwj = 0x200d marks = set(emoji_skin_tone_modifiers) | {zwj} not_assigned = set(range(0, sys.maxunicode)) @@ -110,9 +111,9 @@ def split_two(line): return chars, rest -all_emoji = set() -emoji_categories = {} -emoji_presentation_bases = set() +all_emoji: Set[int] = set() +emoji_categories: Dict[str, Set[int]] = {} +emoji_presentation_bases: Set[int] = set() def parse_emoji(): @@ -130,7 +131,8 @@ def parse_emoji(): emoji_presentation_bases.add(base) -doublewidth, ambiguous = set(), set() +doublewidth: Set[int] = set() +ambiguous: Set[int] = set() def parse_eaw(): diff --git a/publish.py b/publish.py index d5b74c53c..bd398cb59 100755 --- a/publish.py +++ b/publish.py @@ -16,6 +16,7 @@ import sys import tempfile import time from contextlib import suppress +from typing import cast import requests @@ -25,11 +26,11 @@ docs_dir = os.path.abspath('docs') publish_dir = os.path.abspath(os.path.join('..', 'kovidgoyal.github.io', 'kitty')) with open('kitty/constants.py') as f: raw = f.read() -nv = re.search( - r'^version\s+=\s+\((\d+), (\d+), (\d+)\)', raw, flags=re.MULTILINE) +nv = cast(re.Match, re.search( + r'^version\s+=\s+\((\d+), (\d+), (\d+)\)', raw, flags=re.MULTILINE)) version = '%s.%s.%s' % (nv.group(1), nv.group(2), nv.group(3)) -appname = re.search( - r"^appname\s+=\s+'([^']+)'", raw, flags=re.MULTILINE).group(1) +appname = cast(re.Match, re.search( + r"^appname\s+=\s+'([^']+)'", raw, flags=re.MULTILINE)).group(1) ALL_ACTIONS = 'man html build tag sdist upload website'.split() diff --git a/setup.cfg b/setup.cfg index e91e6a828..76d2e79a6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,3 +12,6 @@ blank_line_before_nested_class_or_def = True [isort] combine_as_imports = True multi_line_output = 5 + +[mypy] +files = kitty,kittens,glfw/glfw.py,*.py diff --git a/setup.py b/setup.py index bd9f2e69f..60be8e73c 100755 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ from functools import partial from collections import namedtuple from contextlib import suppress from pathlib import Path +from typing import cast base = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, 'glfw') @@ -29,13 +30,13 @@ build_dir = 'build' constants = os.path.join('kitty', 'constants.py') with open(constants, 'rb') as f: constants = f.read().decode('utf-8') -appname = re.search(r"^appname = '([^']+)'", constants, re.MULTILINE).group(1) +appname = cast(re.Match, re.search(r"^appname = '([^']+)'", constants, re.MULTILINE)).group(1) version = tuple( map( int, - re.search( + cast(re.Match, re.search( r"^version = \((\d+), (\d+), (\d+)\)", constants, re.MULTILINE - ).group(1, 2, 3) + )).group(1, 2, 3) ) ) _plat = sys.platform.lower()