Skip to content

Commit 7485824

Browse files
authored
[tox] Fix a few invalid type annotations (#50)
Some type annotations are using nested types of the TestSuiteDB class. However, these nested types are actually defined in the __init__ method of TestSuiteDB and are hence not accessible as a class member. The easiest fix seems to be to downgrade these type annotations back to comments, at least for now. In a few other places, add missing annotations to make mypy happy and add `# noqa` to work around flake8 flagging imports as unused (when in reality they are required for mypy annotations). Finally, make the mypy test non-optional so it shows up as a failure when we break it. We are clearly missing a lot of annotations, but at least we have a basis that we can build upon and avoid regressing.
1 parent ed246e5 commit 7485824

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

lnt/server/db/fieldchange.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from sqlalchemy.orm.session import Session
55
from sqlalchemy.orm.exc import ObjectDeletedError
66
from typing import Tuple, List
7+
import typing
78

89
import lnt.server.reporting.analysis
910
from lnt.testing.util.commands import timed
@@ -27,7 +28,7 @@ def post_submit_tasks(session, ts, run_id):
2728
regenerate_fieldchanges_for_run(session, ts, run_id)
2829

2930

30-
def delete_fieldchange(session: Session, ts: TestSuiteDB, change: TestSuiteDB.FieldChange) -> List[int]:
31+
def delete_fieldchange(session: Session, ts: TestSuiteDB, change) -> List[int]:
3132
"""Delete this field change. Since it might be attahed to a regression
3233
via regression indicators, fix those up too. If this orphans a regression
3334
delete it as well."""
@@ -36,7 +37,7 @@ def delete_fieldchange(session: Session, ts: TestSuiteDB, change: TestSuiteDB.Fi
3637
filter(ts.RegressionIndicator.field_change_id == change.id). \
3738
all()
3839
# And all the related regressions.
39-
regression_ids = [r.regression_id for r in indicators]
40+
regression_ids: List[int] = [r.regression_id for r in indicators]
4041

4142
# Remove the idicators that point to this change.
4243
for ind in indicators:
@@ -47,13 +48,13 @@ def delete_fieldchange(session: Session, ts: TestSuiteDB, change: TestSuiteDB.Fi
4748

4849
# We might have just created a regression with no changes.
4950
# If so, delete it as well.
50-
deleted_ids = []
51+
deleted_ids: List[int] = []
5152
for r in regression_ids:
5253
remaining = session.query(ts.RegressionIndicator). \
5354
filter(ts.RegressionIndicator.regression_id == r). \
5455
all()
5556
if len(remaining) == 0:
56-
r = session.query(ts.Regression).get(r)
57+
r = typing.cast(int, session.query(ts.Regression).get(r))
5758
logger.info("Deleting regression because it has not changes:" +
5859
repr(r))
5960
session.delete(r)
@@ -224,7 +225,7 @@ def percent_similar(a: str, b: str) -> float:
224225
@timed
225226
def identify_related_changes(session: Session,
226227
ts: TestSuiteDB,
227-
fc: TestSuiteDB.FieldChange,
228+
fc, # TestSuiteDB.FieldChange
228229
active_changes: List) -> Tuple[bool, List]:
229230
"""Can we find a home for this change in some existing regression? If a
230231
match is found add a regression indicator adding this change to that

lnt/server/db/rules/rule_update_fixed_regressions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def is_fixed(session, ts, regression):
3434
return all(fixes)
3535

3636

37-
def impacts(session: Session, ts: TestSuiteDB, run_id: int, regression: TestSuiteDB.Regression) -> bool:
37+
def impacts(session: Session, ts: TestSuiteDB, run_id: int, regression) -> bool:
3838
"""Does this run have a chance of impacting this regression?
3939
4040
This is just to prevent doing a full comparison, so we don't have

lnt/server/ui/views.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import re
55
import time
6+
import typing # noqa: F401
67
from collections import namedtuple, defaultdict
78
from urllib.parse import urlparse, urljoin
89
from io import BytesIO
@@ -20,7 +21,6 @@
2021
from flask_wtf import Form
2122
from sqlalchemy.orm import joinedload
2223
from sqlalchemy.orm.exc import NoResultFound
23-
from typing import Optional
2424
from wtforms import SelectField, StringField, SubmitField
2525
from wtforms.validators import DataRequired, Length
2626

@@ -36,7 +36,7 @@
3636
import lnt.util.ImportData
3737
import lnt.util.stats
3838
from lnt.external.stats import stats as ext_stats
39-
from lnt.server.db import testsuitedb
39+
from lnt.server.db import testsuitedb # noqa: F401
4040
from lnt.server.reporting.analysis import ComparisonResult, calc_geomean
4141
from lnt.server.ui import util
4242
from lnt.server.ui.decorators import frontend, db_route, v4_route
@@ -1844,7 +1844,8 @@ class MatrixOptions(Form):
18441844
limit = SelectField('Size', choices=MATRIX_LIMITS)
18451845

18461846

1847-
def baseline() -> Optional[testsuitedb.TestSuiteDB.Baseline]:
1847+
def baseline():
1848+
# type: () -> typing.Optional[testsuitedb.TestSuiteDB.Baseline]
18481849
"""Get the baseline object from the user's current session baseline value
18491850
or None if one is not defined.
18501851
"""

tox.ini

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ deps =
2424
types-certifi
2525

2626
commands =
27-
# Nowhere close to passing yet, but nice to have. The option
28-
# --no-incremental is currently needed to suppress warnings about
29-
# UpdatedBase when running tests several times. Future versions of
27+
# The option --no-incremental is currently needed to suppress warnings
28+
# about UpdatedBase when running tests several times. Future versions of
3029
# mypy should be checked to see if it can be removed and not get
3130
# warnings after running tox several times.
32-
- mypy --no-incremental --junit-xml=junit-{envname}.xml --ignore-missing-imports lnt
31+
mypy --no-incremental --junit-xml=junit-{envname}.xml --ignore-missing-imports lnt
3332

3433
[testenv:flake8]
3534
skip_install = true

0 commit comments

Comments
 (0)