Philipp Hörist pushed to branch master at gajim / gajim
Commits: f8f4f934 by Philipp Hörist at 2023-01-05T19:44:33+01:00 chore: Update pre-commit deps
- - - - - b81e8ac8 by Philipp Hörist at 2023-01-05T19:55:27+01:00 refactor: Simplify yield and any() checks
- - - - -
28 changed files:
- .pre-commit-config.yaml - gajim/common/configpaths.py - gajim/common/helpers.py - gajim/common/modules/contacts.py - gajim/common/modules/roster.py - gajim/common/storage/archive.py - gajim/gtk/chat_list_stack.py - gajim/gtk/conversation/jump_to_end_button.py - gajim/gtk/conversation/message_widget.py - gajim/gtk/conversation/plain_widget.py - gajim/gtk/conversation/rows/call.py - gajim/gtk/conversation/rows/command_output.py - gajim/gtk/conversation/rows/file_transfer.py - gajim/gtk/conversation/rows/file_transfer_jingle.py - gajim/gtk/conversation/rows/info.py - gajim/gtk/conversation/rows/message.py - gajim/gtk/conversation/rows/muc_join_left.py - gajim/gtk/conversation/rows/muc_subject.py - gajim/gtk/conversation/rows/user_status.py - gajim/gtk/conversation/rows/widgets.py - gajim/gtk/conversation/view.py - gajim/gtk/groupchat_affiliation.py - gajim/gtk/groupchat_outcasts.py - gajim/gtk/preferences.py - gajim/gui/__init__.py - gajim/plugins/gajimplugin.py - gajim/plugins/manifest.py - pyproject.toml
Changes:
===================================== .pre-commit-config.yaml ===================================== @@ -1,6 +1,6 @@ repos: - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.206 + rev: v0.0.211 hooks: - id: ruff exclude: ".githooks/" @@ -15,7 +15,7 @@ repos: - tomli
- repo: https://github.com/RobertCraigie/pyright-python - rev: v1.1.286 + rev: v1.1.287 hooks: - id: pyright pass_filenames: false
===================================== gajim/common/configpaths.py ===================================== @@ -144,8 +144,7 @@ def __getitem__(self, key: str) -> Path: return path
def items(self) -> Generator[tuple[str, PathTupleT], None, None]: - for key, value in self._paths.items(): - yield (key, value) + yield from self._paths.items()
def _prepare(self, path: Path, unique: bool) -> Path: if os.name == 'nt':
===================================== gajim/common/helpers.py ===================================== @@ -1422,10 +1422,7 @@ def warn_about_plain_connection(account: str, ) -> bool: warn = app.settings.get_account_setting( account, 'confirm_unencrypted_connection') - for type_ in connection_types: - if type_.is_plain and warn: - return True - return False + return any(type_.is_plain and warn for type_ in connection_types)
def get_idle_status_message(state: str, status_message: str) -> str:
===================================== gajim/common/modules/contacts.py ===================================== @@ -351,10 +351,8 @@ def is_self(self): return own_jid == self.jid
def supports(self, requested_feature: str) -> bool: - for resource in self.iter_resources(): - if resource.supports(requested_feature): - return True - return False + return any(resource.supports(requested_feature) + for resource in self.iter_resources())
def supports_audio(self) -> bool: if (self.supports(Namespace.JINGLE_ICE_UDP) and @@ -600,10 +598,8 @@ def is_phone(self): if disco_info is None: return False
- for identity in disco_info.identities: - if identity.type == 'phone': - return True - return False + return any(identity.type == 'phone' for + identity in disco_info.identities)
@property def is_available(self) -> bool:
===================================== gajim/common/modules/roster.py ===================================== @@ -204,8 +204,7 @@ def change_group(self, jid: JID, old_group: str, new_group: str) -> None: self._nbxmpp('Roster').set_item(jid, item.name, groups)
def iter(self) -> Iterator[tuple[JID, RosterItem]]: - for jid, data in self._roster.items(): - yield jid, data + yield from self._roster.items()
def iter_contacts(self) -> Iterator[BareContact]: for jid in self._roster:
===================================== gajim/common/storage/archive.py ===================================== @@ -1367,8 +1367,7 @@ def get_messages_for_export(self, results = cursor.fetchmany(10) if not results: break - for result in results: - yield result + yield from results
def remove_history(self, account: str, jid: JID) -> None: '''
===================================== gajim/gtk/chat_list_stack.py ===================================== @@ -309,10 +309,8 @@ def find_chat(self, account: str, jid: JID) -> Optional[ChatList]: def contains_chat(self, account: str, jid: JID, workspace_id: Optional[str] = None) -> bool: if workspace_id is None: - for chat_list in self._chat_lists.values(): - if chat_list.contains_chat(account, jid): - return True - return False + return any(chat_list.contains_chat(account, jid) for + chat_list in self._chat_lists.values())
chat_list = self._chat_lists[workspace_id] return chat_list.contains_chat(account, jid)
===================================== gajim/gtk/conversation/jump_to_end_button.py ===================================== @@ -19,10 +19,9 @@ from gi.repository import GObject from gi.repository import Gtk
+from gajim.common.modules.contacts import BareContact from gajim.common.modules.contacts import GroupchatContact from gajim.common.modules.contacts import GroupchatParticipant -from gajim.common.modules.contacts import BareContact -
ContactT = Union[BareContact, GroupchatContact, GroupchatParticipant]
===================================== gajim/gtk/conversation/message_widget.py ===================================== @@ -14,22 +14,21 @@
from __future__ import annotations
+from typing import cast from typing import Optional from typing import Union -from typing import cast
from gi.repository import Gtk
-from gajim.common.styling import process from gajim.common.styling import ParsingResult from gajim.common.styling import PlainBlock from gajim.common.styling import PreBlock +from gajim.common.styling import process from gajim.common.styling import QuoteBlock
from .code_widget import CodeWidget -from .quote_widget import QuoteWidget from .plain_widget import PlainWidget - +from .quote_widget import QuoteWidget
ContentT = Union[ParsingResult, QuoteBlock]
===================================== gajim/gtk/conversation/plain_widget.py ===================================== @@ -16,10 +16,10 @@
import logging
-from gi.repository import Gtk -from gi.repository import Pango from gi.repository import Gdk from gi.repository import GLib +from gi.repository import Gtk +from gi.repository import Pango
from gajim.common.helpers import open_uri from gajim.common.helpers import parse_uri
===================================== gajim/gtk/conversation/rows/call.py ===================================== @@ -31,10 +31,10 @@ from gajim.common.jingle_session import JingleSession from gajim.common.storage.archive import ConversationRow
+from .base import BaseRow from .widgets import DateTimeLabel from .widgets import NicknameLabel from .widgets import SimpleLabel -from .base import BaseRow
class CallRow(BaseRow):
===================================== gajim/gtk/conversation/rows/command_output.py ===================================== @@ -20,9 +20,9 @@
from gajim.common.const import AvatarSize
+from .base import BaseRow from .widgets import DateTimeLabel from .widgets import SimpleLabel -from .base import BaseRow
class CommandOutputRow(BaseRow):
===================================== gajim/gtk/conversation/rows/file_transfer.py ===================================== @@ -26,12 +26,12 @@ from gajim.common.i18n import _ from gajim.common.modules.httpupload import HTTPFileTransfer
-from .base import BaseRow -from .widgets import DateTimeLabel +from ...builder import get_builder from ...dialogs import ErrorDialog from ...util import EventHelper -from ...builder import get_builder from ...util import format_eta +from .base import BaseRow +from .widgets import DateTimeLabel
class FileTransferRow(BaseRow, EventHelper):
===================================== gajim/gtk/conversation/rows/file_transfer_jingle.py ===================================== @@ -14,8 +14,8 @@
from __future__ import annotations
-from typing import Union from typing import Optional +from typing import Union
import logging import time @@ -30,14 +30,14 @@ from gajim.common import ged from gajim.common.const import AvatarSize from gajim.common.const import KindConstant -from gajim.common.events import FileRequestReceivedEvent -from gajim.common.events import FileRequestSent from gajim.common.events import FileCompleted -from gajim.common.events import FileProgress from gajim.common.events import FileError from gajim.common.events import FileHashError -from gajim.common.events import FileSendError +from gajim.common.events import FileProgress from gajim.common.events import FileRequestError +from gajim.common.events import FileRequestReceivedEvent +from gajim.common.events import FileRequestSent +from gajim.common.events import FileSendError from gajim.common.events import JingleErrorReceived from gajim.common.events import JingleFtCancelledReceived from gajim.common.file_props import FileProp @@ -48,11 +48,11 @@ from gajim.common.modules.contacts import BareContact from gajim.common.storage.archive import ConversationRow
+from ...builder import get_builder +from ...util import format_eta from .base import BaseRow from .widgets import DateTimeLabel from .widgets import NicknameLabel -from ...builder import get_builder -from ...util import format_eta
TransferEventT = Union[FileRequestReceivedEvent, FileRequestSent]
===================================== gajim/gtk/conversation/rows/info.py ===================================== @@ -23,9 +23,9 @@
from gajim.common.const import AvatarSize
+from .base import BaseRow from .widgets import DateTimeLabel from .widgets import SimpleLabel -from .base import BaseRow
class InfoMessage(BaseRow):
===================================== gajim/gtk/conversation/rows/message.py ===================================== @@ -17,17 +17,15 @@ from typing import Optional from typing import Union
+import textwrap from datetime import datetime from datetime import timedelta -import textwrap
+import cairo from gi.repository import GdkPixbuf from gi.repository import GLib from gi.repository import Gtk from gi.repository import Pango - -import cairo - from nbxmpp.errors import StanzaError from nbxmpp.modules.security_labels import Displaymarking from nbxmpp.structs import CommonError @@ -46,16 +44,15 @@ from gajim.common.modules.contacts import GroupchatParticipant from gajim.common.types import ChatContactT
+from ...preview import PreviewWidget +from ...util import format_fingerprint +from ..message_widget import MessageWidget from .base import BaseRow from .widgets import AvatarBox from .widgets import DateTimeLabel -from .widgets import NicknameLabel from .widgets import MessageIcons from .widgets import MoreMenuButton -from ..message_widget import MessageWidget -from ...preview import PreviewWidget -from ...util import format_fingerprint - +from .widgets import NicknameLabel
MERGE_TIMEFRAME = timedelta(seconds=120)
===================================== gajim/gtk/conversation/rows/muc_join_left.py ===================================== @@ -19,12 +19,12 @@
from gi.repository import Gtk
-from gajim.common.i18n import _ from gajim.common.const import AvatarSize +from gajim.common.i18n import _
-from .widgets import SimpleLabel -from .widgets import DateTimeLabel from .base import BaseRow +from .widgets import DateTimeLabel +from .widgets import SimpleLabel
class MUCJoinLeft(BaseRow):
===================================== gajim/gtk/conversation/rows/muc_subject.py ===================================== @@ -25,9 +25,9 @@ from gajim.common.const import AvatarSize from gajim.common.i18n import _
+from ..message_widget import MessageWidget from .base import BaseRow from .widgets import DateTimeLabel -from ..message_widget import MessageWidget
class MUCSubject(BaseRow):
===================================== gajim/gtk/conversation/rows/user_status.py ===================================== @@ -21,15 +21,15 @@
from gi.repository import Gtk
-from gajim.common.i18n import _ from gajim.common.const import AvatarSize from gajim.common.helpers import get_uf_show +from gajim.common.i18n import _
-from .widgets import SimpleLabel -from .widgets import DateTimeLabel -from .base import BaseRow -from ..message_widget import MessageWidget from ...avatar import get_show_circle +from ..message_widget import MessageWidget +from .base import BaseRow +from .widgets import DateTimeLabel +from .widgets import SimpleLabel
class UserStatus(BaseRow):
===================================== gajim/gtk/conversation/rows/widgets.py ===================================== @@ -14,16 +14,16 @@
from __future__ import annotations
-from typing import TYPE_CHECKING from typing import Optional +from typing import TYPE_CHECKING
from datetime import datetime
-from gi.repository import Gtk +import cairo from gi.repository import Gdk -from gi.repository import Pango from gi.repository import GLib -import cairo +from gi.repository import Gtk +from gi.repository import Pango
from gajim.common import app from gajim.common.const import AvatarSize @@ -36,9 +36,9 @@
from ...menus import get_chat_row_menu from ...menus import get_groupchat_participant_menu -from ...util import wrap_with_event_box -from ...util import get_cursor from ...util import GajimPopover +from ...util import get_cursor +from ...util import wrap_with_event_box
class SimpleLabel(Gtk.Label):
===================================== gajim/gtk/conversation/view.py ===================================== @@ -15,53 +15,51 @@ from __future__ import annotations
from typing import Any +from typing import cast +from typing import Generator from typing import Literal from typing import Optional from typing import Union -from typing import Generator -from typing import cast
import logging import time - from datetime import datetime from datetime import timedelta
from gi.repository import Gdk -from gi.repository import Gtk -from gi.repository import GObject from gi.repository import Gio - +from gi.repository import GObject +from gi.repository import Gtk from nbxmpp.errors import StanzaError from nbxmpp.modules.security_labels import Displaymarking +from nbxmpp.protocol import JID from nbxmpp.structs import CommonError from nbxmpp.structs import MucSubject -from nbxmpp.protocol import JID
from gajim.common import app -from gajim.common import types from gajim.common import events +from gajim.common import types from gajim.common.helpers import AdditionalDataDict -from gajim.common.helpers import to_user_string from gajim.common.helpers import get_start_of_day +from gajim.common.helpers import to_user_string +from gajim.common.modules.contacts import BareContact from gajim.common.modules.contacts import GroupchatContact from gajim.common.modules.httpupload import HTTPFileTransfer from gajim.common.storage.archive import ConversationRow -from gajim.common.modules.contacts import BareContact from gajim.common.types import ChatContactT
from .rows.base import BaseRow -from .rows.read_marker import ReadMarkerRow -from .rows.scroll_hint import ScrollHintRow -from .rows.message import MessageRow -from .rows.info import InfoMessage from .rows.call import CallRow from .rows.command_output import CommandOutputRow from .rows.date import DateRow from .rows.file_transfer import FileTransferRow from .rows.file_transfer_jingle import FileTransferJingleRow -from .rows.muc_subject import MUCSubject +from .rows.info import InfoMessage +from .rows.message import MessageRow from .rows.muc_join_left import MUCJoinLeft +from .rows.muc_subject import MUCSubject +from .rows.read_marker import ReadMarkerRow +from .rows.scroll_hint import ScrollHintRow from .rows.user_status import UserStatus
log = logging.getLogger('gajim.gui.conversation_view') @@ -701,8 +699,7 @@ def get_row_by_stanza_id(self, stanza_id: str) -> Optional[MessageRow]: return None
def iter_rows(self) -> Generator[BaseRow, None, None]: - for row in cast(list[BaseRow], self._list_box.get_children()): - yield row + yield from cast(list[BaseRow], self._list_box.get_children())
def remove_rows_by_type(self, row_type: str) -> None: for row in self.iter_rows():
===================================== gajim/gtk/groupchat_affiliation.py ===================================== @@ -179,10 +179,7 @@ def _on_selection_changed(self, tree_selection: Gtk.TreeSelection) -> None: self._set_remove_button_state(sensitive, selected_affiliations)
def _jid_exists(self, jid: str) -> bool: - for row in self._store: - if row[Column.JID] == jid: - return True - return False + return any(row[Column.JID] == jid for row in self._store)
@staticmethod def _get_selected_affiliations(tree_selection: Gtk.TreeSelection
===================================== gajim/gtk/groupchat_outcasts.py ===================================== @@ -144,10 +144,7 @@ def _on_selection_changed(self, tree_selection: Gtk.TreeSelection) -> None: self._set_remove_button_state(sensitive)
def _jid_exists(self, jid: str) -> bool: - for row in self._store: - if row[Column.JID] == jid: - return True - return False + return any(row[Column.JID] == jid for row in self._store)
def _set_remove_button_state(self, sensitive: bool) -> None: value = self._own_affiliation in ('admin', 'owner')
===================================== gajim/gtk/preferences.py ===================================== @@ -916,10 +916,7 @@ def update_proxy_list(self) -> None: popover_row.update_entries(self._get_proxies())
def _check_hints_reset(self) -> bool: - for hint in self._hints_list: - if app.settings.get(hint) is False: - return True - return False + return any(app.settings.get(hint) is False for hint in self._hints_list)
def _on_reset_hints(self, button: Gtk.Button) -> None: for hint in self._hints_list:
===================================== gajim/gui/__init__.py ===================================== @@ -1,15 +1,15 @@
from __future__ import annotations
-from typing import Union -from typing import Sequence from typing import Optional +from typing import Sequence +from typing import Union
-import types import sys +import types from importlib.abc import MetaPathFinder -from importlib.util import spec_from_file_location from importlib.machinery import ModuleSpec +from importlib.util import spec_from_file_location from pathlib import Path
===================================== gajim/plugins/gajimplugin.py ===================================== @@ -146,8 +146,7 @@ def __contains__(self, key: str) -> bool: return key in self.data
def __iter__(self): - for key in self.data: - yield key + yield from self.data
def keys(self): return self.data.keys()
===================================== gajim/plugins/manifest.py ===================================== @@ -98,10 +98,7 @@ def from_path(cls, path: Path) -> PluginManifest: return cls.from_manifest_json(manifest, manifest_path)
def _check_requirements(self) -> bool: - for req in self.requirements: - if GAJIM_VERSION in req.specifier: - return True - return False + return any(GAJIM_VERSION in req.specifier for req in self.requirements)
@classmethod def from_manifest_json(cls,
===================================== pyproject.toml ===================================== @@ -133,6 +133,8 @@ ignore = [ "RUF003", # AmbiguousUnicodeCharacterComment "RUF100", # Unused `noqa` directive "S101", # Use of `assert` detected + "SIM102", # Use a single `if` statement instead of nested `if` statements + "SIM105", # Use `contextlib.suppress(Exception)` instead of try-except-pass "UP007", # Use X | Y for type annotations ]
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/bf7824ae18dbd9b83b297d5ecedaeff5...