From 5a9362fd275e36ca931d4936eb7c40209741759b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 28 May 2023 21:23:36 +0200 Subject: cq: Use union operator in ininstance() calls --- gajim/common/dbus/remote_control.py | 2 +- gajim/common/modules/vcard_avatars.py | 2 +- gajim/common/storage/base.py | 2 +- gajim/gtk/certificate_dialog.py | 2 +- gajim/gtk/chat_list.py | 4 ++-- gajim/gtk/conversation/rows/file_transfer_jingle.py | 2 +- gajim/gtk/conversation/rows/message.py | 2 +- gajim/gtk/conversation/view.py | 4 ++-- pyproject.toml | 1 - 9 files changed, 10 insertions(+), 11 deletions(-) diff --git a/gajim/common/dbus/remote_control.py b/gajim/common/dbus/remote_control.py index d7a254bdb..d80cce7bb 100644 --- a/gajim/common/dbus/remote_control.py +++ b/gajim/common/dbus/remote_control.py @@ -112,7 +112,7 @@ def get_dbus_struct(obj: Any) -> GLib.Variant: return GLib.Variant('d', obj) if isinstance(obj, bool): return GLib.Variant('b', obj) - if isinstance(obj, (list, tuple)): + if isinstance(obj, list | tuple): lst = [get_dbus_struct(i) for i in obj # pyright: ignore if i is not None] result = GLib.Variant('av', lst) diff --git a/gajim/common/modules/vcard_avatars.py b/gajim/common/modules/vcard_avatars.py index 7a8f66a11..95c360477 100644 --- a/gajim/common/modules/vcard_avatars.py +++ b/gajim/common/modules/vcard_avatars.py @@ -96,7 +96,7 @@ class VCardAvatars(BaseModule): self._log.info('Received: %s %s', contact.jid, avatar_sha) app.app.avatar_storage.save_avatar(avatar) - if isinstance(contact, (BareContact, GroupchatContact)): + if isinstance(contact, BareContact | GroupchatContact): contact.set_avatar_sha(avatar_sha) else: diff --git a/gajim/common/storage/base.py b/gajim/common/storage/base.py index 9b60bb1ba..107c1b65d 100644 --- a/gajim/common/storage/base.py +++ b/gajim/common/storage/base.py @@ -119,7 +119,7 @@ class Encoder(json.JSONEncoder): dct['__type'] = 'RosterItem' return dct - if isinstance(o, (Affiliation, Role, StatusCode)): + if isinstance(o, Affiliation | Role | StatusCode): return {'value': o.value, '__type': o.__class__.__name__} diff --git a/gajim/gtk/certificate_dialog.py b/gajim/gtk/certificate_dialog.py index ae46a16c3..2f451f61e 100644 --- a/gajim/gtk/certificate_dialog.py +++ b/gajim/gtk/certificate_dialog.py @@ -130,7 +130,7 @@ class CertificateBox(Gtk.Box): self._pk_size = _('Unknown') if isinstance(public_key, - (RSAPublicKey, DSAPublicKey, EllipticCurvePublicKey)): + RSAPublicKey | DSAPublicKey | EllipticCurvePublicKey): self._pk_size = f'{public_key.key_size} Bit' self._ui.public_key_algorithm.set_text(self._pk_algorithm) diff --git a/gajim/gtk/chat_list.py b/gajim/gtk/chat_list.py index 815b65aa7..144bd491b 100644 --- a/gajim/gtk/chat_list.py +++ b/gajim/gtk/chat_list.py @@ -314,8 +314,8 @@ class ChatList(Gtk.ListBox, EventHelper): return self._chats.get((account, jid)) is not None def process_event(self, event: events.ChatListEventT) -> None: - if isinstance(event, (events.MessageReceived, - events.MamMessageReceived, + if isinstance(event, (events.MessageReceived | + events.MamMessageReceived | events.GcMessageReceived)): self._on_message_received(event) elif isinstance(event, events.MessageUpdated): diff --git a/gajim/gtk/conversation/rows/file_transfer_jingle.py b/gajim/gtk/conversation/rows/file_transfer_jingle.py index 23f16dd0a..a3fc586fe 100644 --- a/gajim/gtk/conversation/rows/file_transfer_jingle.py +++ b/gajim/gtk/conversation/rows/file_transfer_jingle.py @@ -258,7 +258,7 @@ class FileTransferJingleRow(BaseRow): elif isinstance(event, FileHashError): self._ui.action_stack.set_visible_child_name('hash-error') self._ui.transfer_action.set_text(_('File Verification Failed')) - elif isinstance(event, (FileRequestError, FileSendError)): + elif isinstance(event, FileRequestError | FileSendError): self._ui.action_stack.set_visible_child_name('error') self._ui.transfer_action.set_text(_('File Transfer Cancelled')) error_text = _('Connection with %s could not be ' diff --git a/gajim/gtk/conversation/rows/message.py b/gajim/gtk/conversation/rows/message.py index 7da97009a..6544ba422 100644 --- a/gajim/gtk/conversation/rows/message.py +++ b/gajim/gtk/conversation/rows/message.py @@ -115,7 +115,7 @@ class MessageRow(BaseRow): if is_previewable: muc_context = None if isinstance(self._contact, - (GroupchatContact, GroupchatParticipant)): + GroupchatContact | GroupchatParticipant): muc_context = self._contact.muc_context self._message_widget = PreviewWidget(account) app.preview_manager.create_preview( diff --git a/gajim/gtk/conversation/view.py b/gajim/gtk/conversation/view.py index 63b1f3ea1..9c804b865 100644 --- a/gajim/gtk/conversation/view.py +++ b/gajim/gtk/conversation/view.py @@ -390,7 +390,7 @@ class ConversationView(Gtk.ScrolledWindow): def get_first_event_row(self) -> InfoMessage | MUCJoinLeft | None: for row in self._list_box.get_children(): - if isinstance(row, (InfoMessage, MUCJoinLeft)): + if isinstance(row, InfoMessage | MUCJoinLeft): return row return None @@ -398,7 +398,7 @@ class ConversationView(Gtk.ScrolledWindow): children = self._list_box.get_children() children.reverse() for row in children: - if isinstance(row, (InfoMessage, MUCJoinLeft)): + if isinstance(row, InfoMessage | MUCJoinLeft): return row return None diff --git a/pyproject.toml b/pyproject.toml index 5196ff53a..5444ed27c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -234,7 +234,6 @@ ignore = [ "SIM212", # Use `value if value else ''` instead of `'' if not value else value` "SIM300", # Yoda conditions are discouraged use x instead "UP032", # Use f-string instead of `format` call - "UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)` "UP037", # Remove quotes from type annotation ] -- cgit v1.2.3