From 07fe999b95ffe49737c7b7d51fabb5bae58a5780 Mon Sep 17 00:00:00 2001 From: wurstsalat Date: Tue, 29 Nov 2022 19:32:39 +0100 Subject: [PATCH] [length_notifier] Type annotations, linting --- length_notifier/__init__.py | 2 +- length_notifier/config_dialog.py | 38 ++++++++++++++++++++++-------- length_notifier/length_notifier.py | 4 ++-- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/length_notifier/__init__.py b/length_notifier/__init__.py index e84a487..18a51f1 100644 --- a/length_notifier/__init__.py +++ b/length_notifier/__init__.py @@ -1 +1 @@ -from .length_notifier import LengthNotifierPlugin +from .length_notifier import LengthNotifierPlugin # type: ignore diff --git a/length_notifier/config_dialog.py b/length_notifier/config_dialog.py index dbfe8ea..7e1c096 100644 --- a/length_notifier/config_dialog.py +++ b/length_notifier/config_dialog.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # This file is part of Gajim. # # Gajim is free software: you can redistribute it and/or modify @@ -15,6 +13,11 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see . +from __future__ import annotations + +from typing import Any +from typing import TYPE_CHECKING + from gi.repository import GObject from gi.repository import Gtk @@ -26,13 +29,20 @@ from gajim.gui.const import SettingType from gajim.plugins.plugins_i18n import _ +if TYPE_CHECKING: + from .length_notifier import LengthNotifierPlugin + class LengthNotifierConfigDialog(SettingsDialog): - def __init__(self, plugin, parent): + def __init__(self, + plugin: LengthNotifierPlugin, + parent: Gtk.Window + ) -> None: + self.plugin = plugin jids = self.plugin.config['JIDS'] or '' settings = [ - Setting('MessageLengthSpinSetting', + Setting('MessageLengthSpinSetting', # type: ignore _('Message Length'), SettingType.VALUE, self.plugin.config['MESSAGE_WARNING_LENGTH'], @@ -62,11 +72,13 @@ class LengthNotifierConfigDialog(SettingsDialog): SettingsDialog.__init__(self, parent, _('Length Notifier Configuration'), - Gtk.DialogFlags.MODAL, settings, None, - extend=[('MessageLengthSpinSetting', + Gtk.DialogFlags.MODAL, + settings, + '', + extend=[('MessageLengthSpinSetting', # type: ignore SizeSpinSetting)]) - def _on_setting(self, value, data): + def _on_setting(self, value: Any, data: Any) -> None: if isinstance(value, str): value.strip() self.plugin.config[data] = value @@ -76,8 +88,14 @@ class LengthNotifierConfigDialog(SettingsDialog): class SizeSpinSetting(SpinSetting): __gproperties__ = { - "setting-value": (int, 'Size', '', 1, 1000, 140, - GObject.ParamFlags.READWRITE), } + 'setting-value': (int, + 'Size', + '', + 1, + 1000, + 140, + GObject.ParamFlags.READWRITE), + } - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: SpinSetting.__init__(self, *args, **kwargs) diff --git a/length_notifier/length_notifier.py b/length_notifier/length_notifier.py index 8ba5d2e..40a9480 100644 --- a/length_notifier/length_notifier.py +++ b/length_notifier/length_notifier.py @@ -11,7 +11,6 @@ # # You should have received a copy of the GNU General Public License # along with Gajim. If not, see . -# ''' Message length notifier plugin. @@ -23,7 +22,8 @@ Message length notifier plugin. ''' from __future__ import annotations -from typing import Any, cast +from typing import Any +from typing import cast import logging from functools import partial