From 1dee824578b0c485c02a5b12dd4f07c046307a13 Mon Sep 17 00:00:00 2001 From: Andy Chu Date: Thu, 1 Feb 2018 23:07:39 -0800 Subject: [PATCH] Remove all the unused imports. Added that check to the 'fatal' part of the flake8 check. --- asdl/arith_ast_test.py | 1 - asdl/arith_parse.py | 2 +- asdl/asdl_demo.py | 6 ++++-- asdl/encode.py | 2 -- asdl/format.py | 1 - asdl/format_test.py | 3 --- asdl/gen_cpp.py | 1 - asdl/py_meta.py | 12 ++++-------- asdl/py_meta_test.py | 5 +++-- bin/oil.py | 1 - core/builtin.py | 2 -- core/builtin_test.py | 1 - core/cmd_exec.py | 2 -- core/cmd_exec_test.py | 4 ---- core/completion.py | 3 --- core/completion_test.py | 2 -- core/glob_.py | 3 ++- core/lexer.py | 2 +- core/lexer_gen_test.py | 3 +-- core/libstr_test.py | 2 ++ core/process.py | 2 +- core/process_test.py | 3 --- core/reader.py | 1 + core/test_builtin.py | 1 - core/word.py | 1 - core/word_eval.py | 1 - core/word_eval_test.py | 4 +++- core/word_test.py | 2 +- osh/arith_parse.py | 2 -- osh/arith_parse_test.py | 5 ----- osh/ast_gen.py | 1 - osh/bool_parse.py | 2 -- osh/cmd_parse.py | 2 -- osh/cmd_parse_test.py | 3 --- osh/lex.py | 2 +- osh/lex_test.py | 3 +-- osh/parse_lib.py | 2 -- osh/word_parse.py | 2 -- osh/word_parse_test.py | 4 +--- test/lint.sh | 11 +++++++++-- 40 files changed, 36 insertions(+), 76 deletions(-) diff --git a/asdl/arith_ast_test.py b/asdl/arith_ast_test.py index 9642690184..1537eafcdb 100755 --- a/asdl/arith_ast_test.py +++ b/asdl/arith_ast_test.py @@ -6,7 +6,6 @@ import cStringIO import unittest -from asdl import format as fmt from asdl import py_meta from asdl import asdl_ from asdl import const diff --git a/asdl/arith_parse.py b/asdl/arith_parse.py index f707d74bc1..5eacd68e45 100755 --- a/asdl/arith_parse.py +++ b/asdl/arith_parse.py @@ -7,7 +7,7 @@ import sys from asdl import tdop -from asdl.tdop import Node, CompositeNode +from asdl.tdop import CompositeNode from asdl import arith_ast op_id = arith_ast.op_id_e # TODO: Rename this back. diff --git a/asdl/asdl_demo.py b/asdl/asdl_demo.py index c4fded9317..74f34071a3 100755 --- a/asdl/asdl_demo.py +++ b/asdl/asdl_demo.py @@ -12,7 +12,9 @@ from asdl import format as fmt from core.id_kind import Id -from core.util import log +from core import util + +log = util.log def main(argv): @@ -41,7 +43,7 @@ def main(argv): # demo. py_meta.MakeTypes(module, root, type_lookup) - print('Dynamically created a Python module with these types:') + log('Dynamically created a Python module with these types:') for name in dir(root): print('\t' + name) diff --git a/asdl/encode.py b/asdl/encode.py index fbad0d2f56..eaab2192e3 100644 --- a/asdl/encode.py +++ b/asdl/encode.py @@ -2,8 +2,6 @@ encode.py """ -import sys - from asdl import asdl_ as asdl from asdl import py_meta from asdl import const diff --git a/asdl/format.py b/asdl/format.py index 309c7f83b6..78e323ec29 100644 --- a/asdl/format.py +++ b/asdl/format.py @@ -16,7 +16,6 @@ """ import re -import sys from asdl import asdl_ as asdl from core import util diff --git a/asdl/format_test.py b/asdl/format_test.py index e8757ce7f5..c0ce9f1007 100755 --- a/asdl/format_test.py +++ b/asdl/format_test.py @@ -4,12 +4,9 @@ """ import cStringIO -import sys import unittest - from asdl import format as fmt -from asdl import asdl_ from asdl import arith_ast # module under test diff --git a/asdl/gen_cpp.py b/asdl/gen_cpp.py index ec9d86edb9..0e1686c63f 100755 --- a/asdl/gen_cpp.py +++ b/asdl/gen_cpp.py @@ -28,7 +28,6 @@ import sys from asdl import asdl_ as asdl -from asdl import py_meta from asdl import encode TABSIZE = 2 diff --git a/asdl/py_meta.py b/asdl/py_meta.py index 0dc4a63938..d75a448c08 100755 --- a/asdl/py_meta.py +++ b/asdl/py_meta.py @@ -26,13 +26,13 @@ put: an op is Add() and not Add, an instance of a class, not an integer value. """ -import sys - from asdl import asdl_ as asdl from asdl import const from asdl import format as fmt from core import util +log = util.log + def _CheckType(value, expected_desc): """Is value of type expected_desc? @@ -86,12 +86,8 @@ def _CheckType(value, expected_desc): if asdl.is_simple(expected_desc): return actual_desc is expected_desc else: - for cons in expected_desc.types: - #print("CHECKING desc %s against %s" % (desc, cons)) - - # It has to be one of the alternatives - from core.util import log - #log('Checking %s against %s', actual_desc, cons) + for cons in expected_desc.types: # It has to be one of the alternatives + #log("CHECKING desc %s against %s" % (desc, cons)) if actual_desc is cons: return True return False diff --git a/asdl/py_meta_test.py b/asdl/py_meta_test.py index 372840ea13..f6f6e7795e 100755 --- a/asdl/py_meta_test.py +++ b/asdl/py_meta_test.py @@ -3,13 +3,14 @@ py_meta_test.py: Tests for py_meta.py """ -import re import unittest from asdl import py_meta # module under test class AsdlTest(unittest.TestCase): - pass + + def testPyMeta(self): + print py_meta if __name__ == '__main__': diff --git a/bin/oil.py b/bin/oil.py index a533c6ef28..3b4f61c7d4 100755 --- a/bin/oil.py +++ b/bin/oil.py @@ -51,7 +51,6 @@ def _tlog(msg): import errno import platform -import re #import traceback # for debugging # Set in Modules/main.c. diff --git a/core/builtin.py b/core/builtin.py index 1e173ab91a..a7c0aaaa79 100755 --- a/core/builtin.py +++ b/core/builtin.py @@ -30,13 +30,11 @@ import sys from core import args -from core import legacy from core import lexer from core import runtime from core import util from core import state from core import word_compile -from core.id_kind import Id from osh import lex diff --git a/core/builtin_test.py b/core/builtin_test.py index ac38709387..53c66a96b9 100755 --- a/core/builtin_test.py +++ b/core/builtin_test.py @@ -6,7 +6,6 @@ import unittest from core import legacy -from core import lexer from core import builtin # module under test diff --git a/core/cmd_exec.py b/core/cmd_exec.py index 408c7ebf51..580ba0442b 100755 --- a/core/cmd_exec.py +++ b/core/cmd_exec.py @@ -17,7 +17,6 @@ import os import resource -import stat import sys import time @@ -1007,7 +1006,6 @@ def _Dispatch(self, node, fork_external): if not b: break - do_continue = False try: status = self._Execute(node.body) except _ControlFlow as e: diff --git a/core/cmd_exec_test.py b/core/cmd_exec_test.py index 15812a706b..8acf9e8c9d 100755 --- a/core/cmd_exec_test.py +++ b/core/cmd_exec_test.py @@ -9,19 +9,15 @@ cmd_exec_test.py: Tests for cmd_exec.py """ -import os import unittest -from core import alloc from core import builtin from core import cmd_exec # module under test from core.cmd_exec import * from core.id_kind import Id from core import completion from core import legacy -from core import ui from core import word_eval -from core import runtime from core import process from core import test_lib diff --git a/core/completion.py b/core/completion.py index cc7aefb40c..bc66d1e4b8 100755 --- a/core/completion.py +++ b/core/completion.py @@ -33,7 +33,6 @@ import fnmatch import readline import os -import stat import sys import time import traceback @@ -45,7 +44,6 @@ from core import state from core import ui from core import util -from core.id_kind import Id command_e = ast.command_e value_e = runtime.value_e @@ -786,7 +784,6 @@ def Init(pool, builtins, mem, funcs, comp_lookup, status_out, ev): if __name__ == '__main__': from core import builtin - from core import cmd_exec from core import state status_lines = ui.MakeStatusLines() diff --git a/core/completion_test.py b/core/completion_test.py index dfcef35fb3..f4fb6f9ee6 100755 --- a/core/completion_test.py +++ b/core/completion_test.py @@ -12,11 +12,9 @@ import unittest from core import alloc -from core import cmd_exec from core import cmd_exec_test from core import completion # module under test from core import legacy -from core import lexer from core import state from core import test_lib from core import word_eval diff --git a/core/glob_.py b/core/glob_.py index 8d038f369a..02b0ca3595 100644 --- a/core/glob_.py +++ b/core/glob_.py @@ -10,7 +10,8 @@ except ImportError: from benchmarks import fake_libc as libc -from core.util import log +from core import util +log = util.log def LooksLikeGlob(s): diff --git a/core/lexer.py b/core/lexer.py index 93f1f11fce..0b5d8b4cae 100644 --- a/core/lexer.py +++ b/core/lexer.py @@ -16,7 +16,7 @@ from core.id_kind import Id from osh import ast_ as ast -from core.util import log +log = util.log def C(pat, tok_type): diff --git a/core/lexer_gen_test.py b/core/lexer_gen_test.py index 7c9d513c33..7bf4904a8a 100755 --- a/core/lexer_gen_test.py +++ b/core/lexer_gen_test.py @@ -1,11 +1,10 @@ #!/usr/bin/python -S """ -lex_gen_test.py: Tests for lex_gen.py +lexer_gen_test.py: Tests for lexer_gen.py """ import unittest -from osh import lex from core import lexer_gen # module under test diff --git a/core/libstr_test.py b/core/libstr_test.py index 3504ffc2e4..0503e5dc66 100755 --- a/core/libstr_test.py +++ b/core/libstr_test.py @@ -11,6 +11,8 @@ class LibStrTest(unittest.TestCase): def testUnarySuffixOpDemo(self): + print libstr + s = 'abcd' n = len(s) diff --git a/core/process.py b/core/process.py index b8d71a5d95..2fc0dbbf23 100644 --- a/core/process.py +++ b/core/process.py @@ -18,7 +18,7 @@ from core import runtime from core import util -from core.id_kind import Id, REDIR_DEFAULT_FD +from core.id_kind import Id redirect_e = runtime.redirect_e e_die = util.e_die diff --git a/core/process_test.py b/core/process_test.py index 1d31710531..a4ab29b55a 100755 --- a/core/process_test.py +++ b/core/process_test.py @@ -4,7 +4,6 @@ """ import os -import sys import unittest from core.id_kind import Id @@ -49,12 +48,10 @@ def testStdinRedirect(self): r = runtime.PathRedirect(Id.Redir_Less, 0, PATH) fd_state.Push([r], waiter) - #line1 = sys.stdin.readline() line1 = builtin.ReadLineFromStdin() fd_state.Pop() fd_state.Push([r], waiter) - #line2 = sys.stdin.readline() line2 = builtin.ReadLineFromStdin() fd_state.Pop() diff --git a/core/reader.py b/core/reader.py index 913b34c567..c82614fb2b 100644 --- a/core/reader.py +++ b/core/reader.py @@ -12,6 +12,7 @@ import cStringIO from core import util +log = util.log class _Reader(object): diff --git a/core/test_builtin.py b/core/test_builtin.py index 63a4f64548..66e29e7681 100644 --- a/core/test_builtin.py +++ b/core/test_builtin.py @@ -8,7 +8,6 @@ from core import id_kind from core import expr_eval -from core import word from core import runtime from core import util diff --git a/core/word.py b/core/word.py index 8e2ded1d2e..19d1f78c36 100644 --- a/core/word.py +++ b/core/word.py @@ -2,7 +2,6 @@ word.py -- Functions for using words as "tokens". """ -import sys from osh import ast_ as ast from core.id_kind import Id, Kind, LookupKind from core import util diff --git a/core/word_eval.py b/core/word_eval.py index beba54f9d1..f5871d7a19 100644 --- a/core/word_eval.py +++ b/core/word_eval.py @@ -7,7 +7,6 @@ from core import braces from core import expr_eval -from core import legacy from core import libstr from core import glob_ from core.id_kind import Id, Kind, LookupKind diff --git a/core/word_eval_test.py b/core/word_eval_test.py index ca344b419b..5402f55f0d 100755 --- a/core/word_eval_test.py +++ b/core/word_eval_test.py @@ -15,7 +15,9 @@ class WordEvalTest(unittest.TestCase): - pass + + def testWordEval(self): + print word_eval if __name__ == '__main__': diff --git a/core/word_test.py b/core/word_test.py index 45b60294a7..31d06b92a5 100755 --- a/core/word_test.py +++ b/core/word_test.py @@ -11,7 +11,7 @@ class WordTest(unittest.TestCase): def testFoo(self): - print('Hello from word_test.py') + print word if __name__ == '__main__': diff --git a/osh/arith_parse.py b/osh/arith_parse.py index 5344b251fe..0d0fd1a606 100755 --- a/osh/arith_parse.py +++ b/osh/arith_parse.py @@ -3,8 +3,6 @@ arith_parse.py - Parse shell arithmetic, which is based on C. """ -import sys - from core import tdop from core import util from core.id_kind import Id diff --git a/osh/arith_parse_test.py b/osh/arith_parse_test.py index fe25e2af0a..9e6c05a045 100755 --- a/osh/arith_parse_test.py +++ b/osh/arith_parse_test.py @@ -13,9 +13,7 @@ from core import expr_eval from core import legacy -from core import tdop from core import word_eval -from core import cmd_exec from core import state from core import test_lib @@ -30,9 +28,6 @@ class ExprSyntaxError(Exception): def ParseAndEval(code_str): arena = test_lib.MakeArena('') w_parser, _ = parse_lib.MakeParserForCompletion(code_str, arena) - #spec = arith_parse.MakeShellSpec() - #a_parser = tdop.TdopParser(spec, w_parser) # Calls ReadWord(lex_mode_e.ARITH) - #anode = a_parser.Parse() anode = w_parser._ReadArithExpr() # need the right lex state? if not anode: diff --git a/osh/ast_gen.py b/osh/ast_gen.py index 7e4cf9f747..32702bcf3f 100755 --- a/osh/ast_gen.py +++ b/osh/ast_gen.py @@ -5,7 +5,6 @@ import sys -from core import util from osh import ast_ as ast from asdl import gen_cpp diff --git a/osh/bool_parse.py b/osh/bool_parse.py index 77a848cc64..5bfa6d939c 100755 --- a/osh/bool_parse.py +++ b/osh/bool_parse.py @@ -32,8 +32,6 @@ BINARY_OP: -gt, -ot, ==, etc. """ -import sys - from osh import ast_ as ast from core import word diff --git a/osh/cmd_parse.py b/osh/cmd_parse.py index 863a7564bf..c5c90e3f36 100644 --- a/osh/cmd_parse.py +++ b/osh/cmd_parse.py @@ -10,8 +10,6 @@ cmd_parse.py - Parse high level shell commands. """ -import sys - from asdl import const from core import braces diff --git a/osh/cmd_parse_test.py b/osh/cmd_parse_test.py index 60ff0ade36..10df708ea9 100755 --- a/osh/cmd_parse_test.py +++ b/osh/cmd_parse_test.py @@ -6,11 +6,8 @@ import sys import unittest -from asdl import py_meta - from core import ui from core.id_kind import Id -from core.alloc import Pool from core import word from core import test_lib diff --git a/osh/lex.py b/osh/lex.py index 1e98321e3a..291074eb9d 100644 --- a/osh/lex.py +++ b/osh/lex.py @@ -103,10 +103,10 @@ import re from core.id_kind import Id, Kind, ID_SPEC -from core import util from core.lexer import C, R from osh import ast_ as ast + lex_mode_e = ast.lex_mode_e diff --git a/osh/lex_test.py b/osh/lex_test.py index 5cfa3ce87d..05a44a4da0 100755 --- a/osh/lex_test.py +++ b/osh/lex_test.py @@ -5,9 +5,8 @@ import unittest -from core import alloc from core.id_kind import Id, Kind, LookupKind -from core.lexer import CompileAll, Lexer, LineLexer +from core.lexer import CompileAll, LineLexer from core import test_lib from osh import parse_lib diff --git a/osh/parse_lib.py b/osh/parse_lib.py index 6b6d8a9ffe..f6a80db1e5 100644 --- a/osh/parse_lib.py +++ b/osh/parse_lib.py @@ -2,8 +2,6 @@ parse_lib.py - Consolidate various parser instantiations here. """ -import sys - from core import lexer from core import reader from core import id_kind diff --git a/osh/word_parse.py b/osh/word_parse.py index 6894a23765..e8ae7be043 100644 --- a/osh/word_parse.py +++ b/osh/word_parse.py @@ -429,9 +429,7 @@ def _ReadBracedBracedVarSub(self, d_quoted=False): self._Next(lex_mode_e.VS_1) self._Peek() - debug_token = self.cur_token ty = self.token_type - #print("T", debug_token) if ty == Id.VSub_Pound: # Disambiguate diff --git a/osh/word_parse_test.py b/osh/word_parse_test.py index 9230a198ed..dd8ba85e1b 100755 --- a/osh/word_parse_test.py +++ b/osh/word_parse_test.py @@ -15,8 +15,8 @@ from core import alloc from core.id_kind import Id -from core import word from core import test_lib +from core import word from osh import ast_ as ast from osh import parse_lib @@ -491,8 +491,6 @@ def testMultiLine(self): test_lib.AssertAsdlEqual(self, ast.TokenWord(t), w) def testParseErrorLocation(self): - from core import word - w = _assertSpanForWord(self, 'a=(1 2 3)') w = _assertSpanForWord(self, 'foo') diff --git a/test/lint.sh b/test/lint.sh index 87514bbd6d..2953a00b95 100755 --- a/test/lint.sh +++ b/test/lint.sh @@ -99,12 +99,19 @@ bin-flake8() { flake8-all() { local -a dirs=(asdl bin core osh) - # stop the build if there are Python syntax errors or undefined names + + # Step 1: Stop the build if there are Python syntax errors or undefined names bin-flake8 "${dirs[@]}" \ - --count --select=E901,E999,F821,F822,F823 --show-source --statistics + --count --select=E901,E999,F821,F822,F823,F401 --show-source --statistics + + # Step 2: Style errors as warnings. + local ignored='E125,E701,E241,E121,E111,E114,E128,E262,E226,E302,E265,E290,E202,E203,C901' + # trailing whitespace, line too long, blank lines + local ignored_for_now='W291,E501,E303' # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide bin-flake8 "${dirs[@]}" \ + --ignore="$ignored,$ignored_for_now" \ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics }