Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/model_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class MainWindow(QModelMainWindow):
def __init__(self, app: Application):
def __init__(self, app: Application) -> None:
super().__init__(app)

self._cur_file: str = ""
Expand Down
14 changes: 7 additions & 7 deletions demo/multi_file/functions.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
from qtpy.QtWidgets import QApplication, QFileDialog


def open_file():
def open_file() -> None:
name, _ = QFileDialog.getOpenFileName()
print("Open file:", name)


def close():
def close() -> None:
QApplication.activeWindow().close()
print("close")


def undo():
def undo() -> None:
print("undo")


def redo():
def redo() -> None:
print("redo")


def cut():
def cut() -> None:
print("cut")


def copy():
def copy() -> None:
print("copy")


def paste():
def paste() -> None:
print("paste")
30 changes: 15 additions & 15 deletions demo/qapplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


class MainWindow(QMainWindow):
def __init__(self):
def __init__(self) -> None:
super().__init__()

self._cur_file = ""
Expand All @@ -32,28 +32,28 @@ def __init__(self):

self.set_current_file("")

def new_file(self):
def new_file(self) -> None:
if self.maybe_save():
self._text_edit.clear()
self.set_current_file("")

def open(self):
def open(self) -> None:
if self.maybe_save():
fileName, filtr = QFileDialog.getOpenFileName(self)
if fileName:
self.load_file(fileName)

def save(self):
def save(self) -> bool:
return self.save_file(self._cur_file) if self._cur_file else self.save_as()

def save_as(self):
def save_as(self) -> bool:
fileName, filtr = QFileDialog.getSaveFileName(self)
if fileName:
return self.save_file(fileName)

return False

def about(self):
def about(self) -> None:
QMessageBox.about(
self,
"About Application",
Expand All @@ -62,7 +62,7 @@ def about(self):
"toolbars, and a status bar.",
)

def create_actions(self):
def create_actions(self) -> None:
self._new_act = QAction(
fonticon.icon(FA6S.file_circle_plus),
"&New",
Expand Down Expand Up @@ -145,7 +145,7 @@ def create_actions(self):
self._text_edit.copyAvailable.connect(self._cut_act.setEnabled)
self._text_edit.copyAvailable.connect(self._copy_act.setEnabled)

def create_menus(self):
def create_menus(self) -> None:
self._file_menu = self.menuBar().addMenu("&File")
self._file_menu.addAction(self._new_act)
self._file_menu.addAction(self._open_act)
Expand All @@ -164,7 +164,7 @@ def create_menus(self):
self._help_menu = self.menuBar().addMenu("&Help")
self._help_menu.addAction(self._about_act)

def create_tool_bars(self):
def create_tool_bars(self) -> None:
self._file_tool_bar = self.addToolBar("File")
self._file_tool_bar.addAction(self._new_act)
self._file_tool_bar.addAction(self._open_act)
Expand All @@ -175,10 +175,10 @@ def create_tool_bars(self):
self._edit_tool_bar.addAction(self._copy_act)
self._edit_tool_bar.addAction(self._paste_act)

def create_status_bar(self):
def create_status_bar(self) -> None:
self.statusBar().showMessage("Ready")

def maybe_save(self):
def maybe_save(self) -> bool:
if self._text_edit.document().isModified():
ret = QMessageBox.warning(
self,
Expand All @@ -194,7 +194,7 @@ def maybe_save(self):
return False
return True

def load_file(self, fileName):
def load_file(self, fileName: str) -> None:
file = QFile(fileName)
if not file.open(QFile.OpenModeFlag.ReadOnly | QFile.OpenModeFlag.Text):
reason = file.errorString()
Expand All @@ -211,7 +211,7 @@ def load_file(self, fileName):
self.set_current_file(fileName)
self.statusBar().showMessage("File loaded", 2000)

def save_file(self, fileName):
def save_file(self, fileName: str) -> bool:
error = None
QApplication.setOverrideCursor(Qt.WaitCursor)
file = QSaveFile(fileName)
Expand All @@ -234,7 +234,7 @@ def save_file(self, fileName):
self.statusBar().showMessage("File saved", 2000)
return True

def set_current_file(self, fileName: str):
def set_current_file(self, fileName: str) -> None:
self._cur_file = fileName
self._text_edit.document().setModified(False)
self.setWindowModified(False)
Expand All @@ -246,7 +246,7 @@ def set_current_file(self, fileName: str):

self.setWindowTitle(f"{shown_name}[*] - Application")

def stripped_name(self, fullFileName: str):
def stripped_name(self, fullFileName: str) -> str:
return QFileInfo(fullFileName).fileName()


Expand Down
13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,22 @@ select = [
"C4", # flake8-comprehensions
"B", # flake8-bugbear
"A001", # flake8-builtins
# "ANN", # flake8-annotations
"RUF", # ruff-specific rules
"TC", # flake8-type-checking
"TID", # flake8-tidy-imports
"ANN", # flake8-annotations
"RUF", # ruff-specific rules
"TC", # flake8-type-checking
"TID", # flake8-tidy-imports
]
ignore = [
"D401", # First line should be in imperative mood (remove to opt in)
"D401", # First line should be in imperative mood (remove to opt in)
"ANN401", # Disallow typing.Any
]

[tool.ruff.lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true

[tool.ruff.lint.per-file-ignores]
"tests/*.py" = ["D", "E501"]
"tests/*.py" = ["D", "E501", "ANN"]
"demo/*" = ["D"]
"docs/*" = ["D"]
"src/app_model/_registries.py" = ["D10"]
Expand Down
6 changes: 3 additions & 3 deletions src/app_model/backends/qt/_qaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
command_id: str,
app: Application | str,
parent: QObject | None = None,
):
) -> None:
super().__init__(parent)
self._app = Application.get_or_create(app) if isinstance(app, str) else app
self._command_id = command_id
Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(
parent: QObject | None = None,
*,
use_short_title: bool = False,
):
) -> None:
super().__init__(command_rule.id, app, parent)
self._cmd_rule = command_rule
if use_short_title and command_rule.short_title:
Expand Down Expand Up @@ -146,7 +146,7 @@ def __init__(
menu_item: MenuItem,
app: Application | str,
parent: QObject | None = None,
):
) -> None:
super().__init__(menu_item.command, app, parent)
self._menu_item = menu_item
with contextlib.suppress(NameError):
Expand Down
4 changes: 2 additions & 2 deletions src/app_model/backends/qt/_qmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(
app: Application | str,
title: str | None = None,
parent: QWidget | None = None,
):
) -> None:
QMenu.__init__(self, parent)

# NOTE: code duplication with QModelToolBar, but Qt mixins and multiple
Expand Down Expand Up @@ -132,7 +132,7 @@ def __init__(
submenu: SubmenuItem,
app: Application | str,
parent: QWidget | None = None,
):
) -> None:
assert isinstance(submenu, SubmenuItem), f"Expected str, got {type(submenu)!r}"
self._submenu = submenu
super().__init__(
Expand Down
2 changes: 1 addition & 1 deletion src/app_model/expressions/_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def __init__(
op: ast.boolop,
values: Sequence[ConstType | Expr],
**kwargs: Unpack[_Attributes],
):
) -> None:
super().__init__(op, [Expr._cast(v) for v in values], **kwargs)


Expand Down
2 changes: 1 addition & 1 deletion src/app_model/types/_keys/_keybindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class KeyBinding:

parts: list[SimpleKeyBinding] = Field(..., **MIN1) # type: ignore

def __init__(self, *, parts: list[SimpleKeyBinding]):
def __init__(self, *, parts: list[SimpleKeyBinding]) -> None:
self.parts = parts

def __str__(self) -> str:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def test_register_action_decorator(
if mode == "decorator":

@register_action(app=app, id_or_action=cmd_id, **kwargs)
def f1():
def f1() -> str:
return "hi"

assert f1() == "hi" # decorator returns the function

else:

def f2():
def f2() -> str:
return "hi"

if mode == "str":
Expand Down Expand Up @@ -99,14 +99,14 @@ def f2():
assert not list(app.menus)


def test_errors(simple_app: Application):
def test_errors(simple_app: Application) -> None:
with pytest.raises(ValueError, match="'title' is required"):
simple_app.register_action("cmd_id") # type: ignore
with pytest.raises(TypeError, match="must be a string or an Action"):
simple_app.register_action(None) # type: ignore


def test_register_multiple_actions(simple_app: Application):
def test_register_multiple_actions(simple_app: Application) -> None:
actions: list[Action] = [
Action(id="cmd_id1", title="title1", callback=lambda: None),
Action(id="cmd_id2", title="title2", callback=lambda: None),
Expand Down
6 changes: 3 additions & 3 deletions tests/test_context/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app_model.expressions._context import _OBJ_TO_CONTEXT


def test_create_context():
def test_create_context() -> None:
"""You can create a context for any object"""

class T: ...
Expand All @@ -30,7 +30,7 @@ class T: ...
create_context(T(), root={}) # type: ignore


def test_create_and_get_scoped_contexts():
def test_create_and_get_scoped_contexts() -> None:
"""Test that objects created in the stack of another contexted object.

likely the most common way that this API will be used:
Expand Down Expand Up @@ -61,7 +61,7 @@ def __init__(self) -> None:
assert len(_OBJ_TO_CONTEXT) == before


def test_context_events():
def test_context_events() -> None:
"""Changing context keys emits an event"""
mock = Mock()
root = Context()
Expand Down
Loading