Skip to content

Commit

Permalink
Enable some strict mypy options as a first step to fully strict mode.
Browse files Browse the repository at this point in the history
Enable options that only require little to no code fixes.

Signed-off-by: Chris PeBenito <[email protected]>
  • Loading branch information
pebenito committed Feb 14, 2024
1 parent 66a0fad commit 267c402
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 15 deletions.
19 changes: 18 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.*',
Expand Down
2 changes: 1 addition & 1 deletion setools/nodeconquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setoolsgui/apol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setoolsgui/widgets/criteria/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion setoolsgui/widgets/details/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions setoolsgui/widgets/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: LGPL-2.1-only

from . import typing

from .boolean import *
from .bounds import *
from .common import *
Expand Down
2 changes: 1 addition & 1 deletion setoolsgui/widgets/models/terule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions setoolsgui/widgets/models/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions setoolsgui/widgets/tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions setoolsgui/widgets/views/tableview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 267c402

Please sign in to comment.