From 267c4023846cb2e02edb75d65dbca3f62dc74cfe Mon Sep 17 00:00:00 2001 From: Chris PeBenito Date: Wed, 14 Feb 2024 08:46:19 -0500 Subject: [PATCH] Enable some strict mypy options as a first step to fully strict mode. Enable options that only require little to no code fixes. Signed-off-by: Chris PeBenito --- pyproject.toml | 19 ++++++++++++++++++- setools/nodeconquery.py | 2 +- setoolsgui/apol.py | 2 +- setoolsgui/widgets/criteria/name.py | 2 +- setoolsgui/widgets/details/util.py | 2 +- setoolsgui/widgets/models/__init__.py | 2 ++ setoolsgui/widgets/models/terule.py | 2 +- setoolsgui/widgets/models/typing.py | 4 +--- setoolsgui/widgets/tab.py | 3 +-- setoolsgui/widgets/views/tableview.py | 8 ++++---- 10 files changed, 31 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 342f7b26..a7a28828 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,8 +22,25 @@ exclude_lines = ["pragma: no cover", # Mypy config # [tool.mypy] -no_implicit_optional = true +allow_redefinition = false +allow_untyped_globals = false +disallow_any_decorated = false +disallow_any_explicit = false +disallow_any_expr = false +disallow_any_generics = false +disallow_any_unimported = false +disallow_subclassing_any = true +implicit_optional = false +local_partial_types = false +strict_concatenate = true +strict_equality = false +strict_optional = true pretty = true +warn_redundant_casts = true +warn_unused_ignores = true +warn_no_return = true +warn_return_any = false +warn_unreachable = true [[tool.mypy.overrides]] module = ['networkx.*', diff --git a/setools/nodeconquery.py b/setools/nodeconquery.py index 493249bc..533cda9d 100644 --- a/setools/nodeconquery.py +++ b/setools/nodeconquery.py @@ -87,7 +87,7 @@ def results(self) -> Iterable[Nodecon]: if self.network: if self.network_overlap: - if not self.network.overlaps(nodecon.network): # type: ignore + if not self.network.overlaps(nodecon.network): continue else: if not nodecon.network == self.network: diff --git a/setoolsgui/apol.py b/setoolsgui/apol.py index 2698c6d8..eea56256 100644 --- a/setoolsgui/apol.py +++ b/setoolsgui/apol.py @@ -943,7 +943,7 @@ def __init__(self, mls: bool, parent: ApolWorkspace): # populate the analysis choices tree: self.analysis_choices = \ - defaultdict[str, dict[str, widgets.tab.BaseAnalysisTabWidget]](dict) + defaultdict[str, dict[str, type[widgets.tab.BaseAnalysisTabWidget]]](dict) for clsobj in widgets.tab.TAB_REGISTRY.values(): self.analysis_choices[clsobj.section.name][clsobj.tab_title] = clsobj diff --git a/setoolsgui/widgets/criteria/name.py b/setoolsgui/widgets/criteria/name.py index 9510e5c2..9a87295f 100644 --- a/setoolsgui/widgets/criteria/name.py +++ b/setoolsgui/widgets/criteria/name.py @@ -203,7 +203,7 @@ def set_regex(self, state: bool) -> None: # change line edit validator with suppress(AttributeError): # May not have a validator if state: - self.criteria.setValidator(None) # type: ignore + self.criteria.setValidator(None) else: self.criteria.setValidator(self.exact_validator) diff --git a/setoolsgui/widgets/details/util.py b/setoolsgui/widgets/details/util.py index 85475f41..9b40716c 100644 --- a/setoolsgui/widgets/details/util.py +++ b/setoolsgui/widgets/details/util.py @@ -31,7 +31,7 @@ def display_object_details(title: str, html_text: str, buttonBox = QtWidgets.QDialogButtonBox(popup) buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal) buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Close) - buttonBox.clicked.connect(popup.close) # type: ignore + buttonBox.clicked.connect(popup.close) layout.addWidget(buttonBox) QtCore.QMetaObject.connectSlotsByName(popup) diff --git a/setoolsgui/widgets/models/__init__.py b/setoolsgui/widgets/models/__init__.py index 3f91345e..4df42d80 100644 --- a/setoolsgui/widgets/models/__init__.py +++ b/setoolsgui/widgets/models/__init__.py @@ -1,5 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-only +from . import typing + from .boolean import * from .bounds import * from .common import * diff --git a/setoolsgui/widgets/models/terule.py b/setoolsgui/widgets/models/terule.py index 209692f7..bbfeb55a 100644 --- a/setoolsgui/widgets/models/terule.py +++ b/setoolsgui/widgets/models/terule.py @@ -49,7 +49,7 @@ def data(self, index: QtCore.QModelIndex, role: int = ModelRoles.DisplayRole): else: return ", ".join(sorted(rule.perms)) # type: ignore except RuleUseError: - return rule.default.name # type: ignore + return rule.default.name case 5: with suppress(RuleNotConditional): return str(rule.conditional) diff --git a/setoolsgui/widgets/models/typing.py b/setoolsgui/widgets/models/typing.py index e8314612..7b8a3652 100644 --- a/setoolsgui/widgets/models/typing.py +++ b/setoolsgui/widgets/models/typing.py @@ -13,10 +13,8 @@ # This is the return type for the ModelRoles.ContextMenuRole role ContextMenuType = tuple[QtGui.QAction, ...] -QObjectType: type = type(QtCore.QObject) - -class MetaclassFix(QObjectType, abc.ABC): +class MetaclassFix(type(QtCore.QObject), abc.ABC): # type: ignore[misc] """ Fix metaclass issues. diff --git a/setoolsgui/widgets/tab.py b/setoolsgui/widgets/tab.py index 4c7ca445..3918b87e 100644 --- a/setoolsgui/widgets/tab.py +++ b/setoolsgui/widgets/tab.py @@ -9,7 +9,6 @@ import setools from . import criteria, exception, models, util, views -from .models.typing import QObjectType from .queryupdater import QueryResultsUpdater # workspace settings keys @@ -40,7 +39,7 @@ class AnalysisSection(enum.Enum): Rules = 6 -class TabRegistry(QObjectType): +class TabRegistry(models.typing.MetaclassFix): """ Analysis tab registry metaclass. This registers tabs to be used both for diff --git a/setoolsgui/widgets/views/tableview.py b/setoolsgui/widgets/views/tableview.py index daebf9eb..a1630bf8 100644 --- a/setoolsgui/widgets/views/tableview.py +++ b/setoolsgui/widgets/views/tableview.py @@ -44,10 +44,10 @@ def copy(self) -> None: datamodel = self.model() selected_text = [] - current_row = None - current_col = None - prev_row = None - prev_col = None + current_row: int = -1 + current_col: int = -1 + prev_row: int = -1 + prev_col: int = -1 for index in sorted(self.selectionModel().selectedIndexes()): current_row = index.row() current_col = index.column()