diff --git a/lib/config.py b/lib/config.py index 9714928..1219bf7 100644 --- a/lib/config.py +++ b/lib/config.py @@ -44,7 +44,7 @@ specified by an environment variable is not an integer, it is ignored. from __future__ import print_function import os -from pygments.styles import get_all_styles +from pygments.styles import get_all_styles # type: ignore #def get_all_styles(): # return [] diff --git a/lib/fmt/internal.py b/lib/fmt/internal.py index a30ab95..945c676 100644 --- a/lib/fmt/internal.py +++ b/lib/fmt/internal.py @@ -5,8 +5,8 @@ Will be merged with panela later. import re -from colorama import Fore, Back, Style -import colored +from colorama import Fore, Back, Style # type: ignore +import colored # type: ignore PALETTES = { 0: { diff --git a/lib/fmt/markdown.py b/lib/fmt/markdown.py index e120a8c..5d8a050 100644 --- a/lib/fmt/markdown.py +++ b/lib/fmt/markdown.py @@ -8,8 +8,8 @@ Uses external pygments formatters for highlighting (passed as an argument). """ import re -import ansiwrap -import colored +import ansiwrap # type: ignore +import colored # type: ignore def format_text(text, config=None, highlighter=None): """ diff --git a/lib/frontend/ansi.py b/lib/frontend/ansi.py index 276d58b..fbeb28e 100644 --- a/lib/frontend/ansi.py +++ b/lib/frontend/ansi.py @@ -26,9 +26,9 @@ import os import sys import re -import colored -from pygments import highlight as pygments_highlight -from pygments.formatters import Terminal256Formatter # pylint: disable=no-name-in-module +import colored # type: ignore +from pygments import highlight as pygments_highlight # type: ignore +from pygments.formatters import Terminal256Formatter # type: ignore # pylint: disable=no-name-in-module # pylint: disable=wrong-import-position sys.path.append(os.path.abspath(os.path.join(__file__, '..'))) from config import CONFIG diff --git a/lib/languages_data.py b/lib/languages_data.py index fa65953..e13e469 100644 --- a/lib/languages_data.py +++ b/lib/languages_data.py @@ -6,7 +6,9 @@ from the project tree. """ -import pygments.lexers +from typing import Dict + +import pygments.lexers # type: ignore LEXER = { "assembly" : pygments.lexers.NasmLexer, @@ -85,7 +87,7 @@ LEXER = { } # canonical names are on the right side -LANGUAGE_ALIAS = { +LANGUAGE_ALIAS: Dict[str, str] = { 'asm' : 'assembly', 'assembler' : 'assembly', 'c++' : 'cpp', @@ -108,7 +110,7 @@ LANGUAGE_ALIAS = { 'm' : 'octave', } -VIM_NAME = { +VIM_NAME: Dict[str, str] = { 'assembly' : 'asm', 'bash' : 'sh', 'coffeescript': 'coffee', @@ -135,7 +137,7 @@ VIM_NAME = { 'flask' : 'python', } -SO_NAME = { +SO_NAME: Dict[str, str] = { 'coffee' : 'coffeescript', 'js' : 'javascript', 'python3' : 'python-3.x', @@ -149,10 +151,10 @@ SO_NAME = { # into canonical cheat.sh names # -ATOM_FT_NAME = { +ATOM_FT_NAME: Dict[str, str] = { } -EMACS_FT_NAME = { +EMACS_FT_NAME: Dict[str, str] = { "asm-mode" : "asm", "awk-mode" : "awk", "sh-mode" : "bash", @@ -217,16 +219,16 @@ EMACS_FT_NAME = { # vim } -SUBLIME_FT_NAME = { +SUBLIME_FT_NAME: Dict[str, str] = { } -VIM_FT_NAME = { +VIM_FT_NAME: Dict[str, str] = { 'asm': 'assembler', 'javascript': 'js', 'octave': 'matlab', } -VSCODE_FT_NAME = { +VSCODE_FT_NAME: Dict[str, str] = { } def rewrite_editor_section_name(section_name): diff --git a/requirements.txt b/requirements.txt index d74ff77..885e58e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,3 +15,4 @@ pycld2 colorama pyyaml python-Levenshtein +pylint diff --git a/tests/mypy.sh b/tests/mypy.sh new file mode 100755 index 0000000..424b01b --- /dev/null +++ b/tests/mypy.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +SKIP_FILES=( + lib/adapter/adapter.py + lib/adapter/cmd.py + lib/adapter/latenz.py + lib/adapter/learnxiny.py + lib/adapter/question.py + lib/adapter/internal.py +) + +contains_element () { + local e match="$1" + shift + for e; do [[ "$e" == "$match" ]] && return 0; done + return 1 +} + +_mypy() { + local file + local result=0 + + # mypy lib/*.py lib/fmt/*.py lib/frontend/*.py + + for file in lib/*.py lib/fmt/*.py lib/frontend/*.py lib/adapter/*.py + do + contains_element "$file" "${SKIP_FILES[@]}" && continue + mypy --follow-imports=skip "$file" || result=1 + done + + return "$result" +} + +_mypy