Skip to content

Commit da59ce3

Browse files
authored
Fix various Flake8 issues in the codebase (#43)
This patch fixes various Flake8 issues in the codebase to make the Github Actions CI closer to passing. Issues were related to whitespace, unused imports, bad indentation, etc. Most missing imports were caused by typing annotations that were only in comments. I upgraded those to actual type annotations when Tox was complaining, except for a few __all__ instances: I really don't think there is a large benefit from using strong typing for the __all__ module variable.
1 parent de742ec commit da59ce3

22 files changed

+39
-63
lines changed

lnt/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,4 @@
33
__versioninfo__ = (0, 4, 2)
44
__version__ = '.'.join(map(str, __versioninfo__)) + '.dev0'
55

6-
# lnt module is imported from the setup script before modules are installed so
7-
# modules might not be available.
8-
try:
9-
from typing import Sequence
10-
except Exception:
11-
pass
12-
13-
__all__ = [] # type: Sequence[str]
6+
__all__ = []

lnt/formats/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from .PlistFormat import format as plist
1212
from .JSONFormat import format as json
1313

14-
formats = [plist, json] # type: List[Dict]
15-
formats_by_name = dict((f['name'], f) for f in formats) # type: Dict[str, Dict]
16-
format_names = list(formats_by_name.keys()) # type: List[str]
14+
formats: List[Dict] = [plist, json]
15+
formats_by_name: Dict[str, Dict] = dict((f['name'], f) for f in formats)
16+
format_names: List[str] = list(formats_by_name.keys())
1717

1818

1919
def get_format(name):

lnt/server/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
from typing import Sequence
2-
3-
__all__ = [] # type: Sequence[str]
1+
__all__ = []

lnt/server/db/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
from typing import Sequence
2-
3-
__all__ = [] # type: Sequence[str]
1+
__all__ = []

lnt/server/db/fieldchange.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def post_submit_tasks(session, ts, run_id):
2727
regenerate_fieldchanges_for_run(session, ts, run_id)
2828

2929

30-
def delete_fieldchange(session, ts, change):
31-
# type: (Session, TestSuiteDB, TestSuiteDB.FieldChange) -> List[int]
30+
def delete_fieldchange(session: Session, ts: TestSuiteDB, change: TestSuiteDB.FieldChange) -> List[int]:
3231
"""Delete this field change. Since it might be attahed to a regression
3332
via regression indicators, fix those up too. If this orphans a regression
3433
delete it as well."""
@@ -64,8 +63,7 @@ def delete_fieldchange(session, ts, change):
6463

6564

6665
@timed
67-
def regenerate_fieldchanges_for_run(session, ts, run_id):
68-
# type: (Session, TestSuiteDB, int) -> None
66+
def regenerate_fieldchanges_for_run(session: Session, ts: TestSuiteDB, run_id: int) -> None:
6967
"""Regenerate the set of FieldChange objects for the given run.
7068
"""
7169
# Allow for potentially a few different runs, previous_runs, next_runs
@@ -213,8 +211,7 @@ def is_overlaping(fc1, fc2):
213211
(r1_min < r2_max and r2_min < r1_max)
214212

215213

216-
def percent_similar(a, b):
217-
# type: (str, str) -> float
214+
def percent_similar(a: str, b: str) -> float:
218215
"""
219216
Percent similar: are these strings similar to each other?
220217
:param a: first string
@@ -225,8 +222,10 @@ def percent_similar(a, b):
225222

226223

227224
@timed
228-
def identify_related_changes(session, ts, fc, active_changes):
229-
# type: (Session, TestSuiteDB, TestSuiteDB.FieldChange, List) -> Tuple[bool, List]
225+
def identify_related_changes(session: Session,
226+
ts: TestSuiteDB,
227+
fc: TestSuiteDB.FieldChange,
228+
active_changes: List) -> Tuple[bool, List]:
230229
"""Can we find a home for this change in some existing regression? If a
231230
match is found add a regression indicator adding this change to that
232231
regression, otherwise create a new regression for this change.

lnt/server/db/migrations/upgrade_2_to_3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def upgrade_testsuite(engine, session, name):
4646
# Grab Test Suite.
4747
test_suite = session.query(upgrade_0_to_1.TestSuite).\
4848
filter_by(name=name).first()
49-
assert(test_suite is not None)
49+
assert test_suite is not None
5050

5151
# Add FieldChange to the test suite.
5252
Base = add_fieldchange(test_suite)

lnt/server/db/migrations/upgrade_7_to_8.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def upgrade_testsuite(engine, session, name):
8787
# Grab Test Suite.
8888
test_suite = session.query(upgrade_0_to_1.TestSuite).\
8989
filter_by(name=name).first()
90-
assert(test_suite is not None)
90+
assert test_suite is not None
9191

9292
# Add FieldChange to the test suite.
9393
Base = add_regressions(test_suite)

lnt/server/db/rules/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
from typing import Sequence
2-
3-
__all__ = [] # type: Sequence[str]
1+
__all__ = []

lnt/server/db/rules/rule_update_fixed_regressions.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def is_fixed(session, ts, regression):
3434
return all(fixes)
3535

3636

37-
def impacts(session, ts, run_id, regression):
38-
# type: (Session, TestSuiteDB, int, TestSuiteDB.Regression) -> bool
37+
def impacts(session: Session, ts: TestSuiteDB, run_id: int, regression: TestSuiteDB.Regression) -> bool:
3938
"""Does this run have a chance of impacting this regression?
4039
4140
This is just to prevent doing a full comparison, so we don't have
@@ -51,8 +50,7 @@ def impacts(session, ts, run_id, regression):
5150
return machine_id in regression_machines_set
5251

5352

54-
def age_out_oldest_regressions(session, ts, num_to_keep=50):
55-
# type: (Session, TestSuiteDB, int) -> int
53+
def age_out_oldest_regressions(session: Session, ts: TestSuiteDB, num_to_keep: int = 50) -> int:
5654
"""Find the oldest regressions that are still in the detected state,
5755
and age them out. This is needed when regressions are not manually
5856
acknowledged, regression analysis can grow unbounded.
@@ -69,7 +67,7 @@ def age_out_oldest_regressions(session, ts, num_to_keep=50):
6967
.join(ts.FieldChange) \
7068
.all()
7169

72-
regression_newest_change = {} # type: Dict[int, int]
70+
regression_newest_change: Dict[int, int] = {}
7371
for regression_id, order_id in regression_orders:
7472
current = regression_newest_change.get(regression_id)
7573
if current is None or current < order_id:

lnt/server/db/rules_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ def load_rules():
4949

5050

5151
# Places our rules can hook to.
52-
HOOKS = {
52+
HOOKS: Dict['str', List[Callable]] = {
5353
'post_test_hook': [],
5454
'post_submission_hook': [],
5555
'post_regression_create_hook': [],
5656
'is_useful_change': [],
57-
} # type: Dict['str', List[Callable]]
57+
}
5858

5959
DESCRIPTIONS = {}
6060
HOOKS_LOADED = False

0 commit comments

Comments
 (0)