From 90fc9b4533cd9f949a48ae93b0943be4673e61bc Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Fri, 3 Oct 2025 11:29:49 -0400 Subject: [PATCH] [tox] Fix a few invalid type annotations 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. --- lnt/server/db/fieldchange.py | 11 ++++++----- lnt/server/db/rules/rule_update_fixed_regressions.py | 2 +- lnt/server/ui/views.py | 7 ++++--- tox.ini | 7 +++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lnt/server/db/fieldchange.py b/lnt/server/db/fieldchange.py index 78d0838a..fdf3885e 100644 --- a/lnt/server/db/fieldchange.py +++ b/lnt/server/db/fieldchange.py @@ -4,6 +4,7 @@ from sqlalchemy.orm.session import Session from sqlalchemy.orm.exc import ObjectDeletedError from typing import Tuple, List +import typing import lnt.server.reporting.analysis from lnt.testing.util.commands import timed @@ -27,7 +28,7 @@ def post_submit_tasks(session, ts, run_id): regenerate_fieldchanges_for_run(session, ts, run_id) -def delete_fieldchange(session: Session, ts: TestSuiteDB, change: TestSuiteDB.FieldChange) -> List[int]: +def delete_fieldchange(session: Session, ts: TestSuiteDB, change) -> List[int]: """Delete this field change. Since it might be attahed to a regression via regression indicators, fix those up too. If this orphans a regression delete it as well.""" @@ -36,7 +37,7 @@ def delete_fieldchange(session: Session, ts: TestSuiteDB, change: TestSuiteDB.Fi filter(ts.RegressionIndicator.field_change_id == change.id). \ all() # And all the related regressions. - regression_ids = [r.regression_id for r in indicators] + regression_ids: List[int] = [r.regression_id for r in indicators] # Remove the idicators that point to this change. for ind in indicators: @@ -47,13 +48,13 @@ def delete_fieldchange(session: Session, ts: TestSuiteDB, change: TestSuiteDB.Fi # We might have just created a regression with no changes. # If so, delete it as well. - deleted_ids = [] + deleted_ids: List[int] = [] for r in regression_ids: remaining = session.query(ts.RegressionIndicator). \ filter(ts.RegressionIndicator.regression_id == r). \ all() if len(remaining) == 0: - r = session.query(ts.Regression).get(r) + r = typing.cast(int, session.query(ts.Regression).get(r)) logger.info("Deleting regression because it has not changes:" + repr(r)) session.delete(r) @@ -224,7 +225,7 @@ def percent_similar(a: str, b: str) -> float: @timed def identify_related_changes(session: Session, ts: TestSuiteDB, - fc: TestSuiteDB.FieldChange, + fc, # TestSuiteDB.FieldChange active_changes: List) -> Tuple[bool, List]: """Can we find a home for this change in some existing regression? If a match is found add a regression indicator adding this change to that diff --git a/lnt/server/db/rules/rule_update_fixed_regressions.py b/lnt/server/db/rules/rule_update_fixed_regressions.py index 6224060f..50f6b56e 100644 --- a/lnt/server/db/rules/rule_update_fixed_regressions.py +++ b/lnt/server/db/rules/rule_update_fixed_regressions.py @@ -34,7 +34,7 @@ def is_fixed(session, ts, regression): return all(fixes) -def impacts(session: Session, ts: TestSuiteDB, run_id: int, regression: TestSuiteDB.Regression) -> bool: +def impacts(session: Session, ts: TestSuiteDB, run_id: int, regression) -> bool: """Does this run have a chance of impacting this regression? This is just to prevent doing a full comparison, so we don't have diff --git a/lnt/server/ui/views.py b/lnt/server/ui/views.py index 15ab2aff..91191e9b 100644 --- a/lnt/server/ui/views.py +++ b/lnt/server/ui/views.py @@ -3,6 +3,7 @@ import os import re import time +import typing # noqa: F401 from collections import namedtuple, defaultdict from urllib.parse import urlparse, urljoin from io import BytesIO @@ -20,7 +21,6 @@ from flask_wtf import Form from sqlalchemy.orm import joinedload from sqlalchemy.orm.exc import NoResultFound -from typing import Optional from wtforms import SelectField, StringField, SubmitField from wtforms.validators import DataRequired, Length @@ -36,7 +36,7 @@ import lnt.util.ImportData import lnt.util.stats from lnt.external.stats import stats as ext_stats -from lnt.server.db import testsuitedb +from lnt.server.db import testsuitedb # noqa: F401 from lnt.server.reporting.analysis import ComparisonResult, calc_geomean from lnt.server.ui import util from lnt.server.ui.decorators import frontend, db_route, v4_route @@ -1844,7 +1844,8 @@ class MatrixOptions(Form): limit = SelectField('Size', choices=MATRIX_LIMITS) -def baseline() -> Optional[testsuitedb.TestSuiteDB.Baseline]: +def baseline(): + # type: () -> typing.Optional[testsuitedb.TestSuiteDB.Baseline] """Get the baseline object from the user's current session baseline value or None if one is not defined. """ diff --git a/tox.ini b/tox.ini index 605bce7d..75f2c8d1 100644 --- a/tox.ini +++ b/tox.ini @@ -24,12 +24,11 @@ deps = types-certifi commands = - # Nowhere close to passing yet, but nice to have. The option - # --no-incremental is currently needed to suppress warnings about - # UpdatedBase when running tests several times. Future versions of + # The option --no-incremental is currently needed to suppress warnings + # about UpdatedBase when running tests several times. Future versions of # mypy should be checked to see if it can be removed and not get # warnings after running tox several times. - - mypy --no-incremental --junit-xml=junit-{envname}.xml --ignore-missing-imports lnt + mypy --no-incremental --junit-xml=junit-{envname}.xml --ignore-missing-imports lnt [testenv:flake8] skip_install = true