diff options
author | Philipp Hörist <philipp@hoerist.com> | 2023-02-01 23:47:11 +0300 |
---|---|---|
committer | Philipp Hörist <philipp@hoerist.com> | 2023-02-03 02:34:01 +0300 |
commit | b5d9231e2e38d0d53b3f3544de79e0c880373918 (patch) | |
tree | 99cd224671e28aa04b58890cfec3865a4cd66c7d | |
parent | 27f65cf69c484b7449205603f32872f34a916ffa (diff) |
refactor: Fix unnecessary comparisons
36 files changed, 79 insertions, 97 deletions
diff --git a/gajim/common/application.py b/gajim/common/application.py index a7ee66f46..c62e2bdaa 100644 --- a/gajim/common/application.py +++ b/gajim/common/application.py @@ -337,10 +337,10 @@ class CoreApplication(ged.EventHelper): username: str, domain: str, password: str, - proxy_name: str, + proxy_name: str | None, custom_host: tuple[str, ConnectionProtocol, - ConnectionType], + ConnectionType] | None, anonymous: bool = False ) -> None: @@ -427,8 +427,7 @@ class CoreApplication(ged.EventHelper): account: Optional[str] = None ) -> None: - if status is None: - status = get_global_show() + status = get_global_show() if account is not None: self._change_status(account, status) diff --git a/gajim/common/call_manager.py b/gajim/common/call_manager.py index fb75a744a..852e894ad 100644 --- a/gajim/common/call_manager.py +++ b/gajim/common/call_manager.py @@ -35,8 +35,8 @@ class CallManager(EventHelper): self._jingle_audio_sid: Optional[str] = None self._jingle_video_sid: Optional[str] = None - self._jingle_audio_state = JingleState.NULL - self._jingle_video_state = JingleState.NULL + self._jingle_audio_state: JingleState = JingleState.NULL + self._jingle_video_state: JingleState = JingleState.NULL # Helper for upgrading voice call to voice + video without # having to show a new call row diff --git a/gajim/common/dbus/music_track.py b/gajim/common/dbus/music_track.py index 6a930b172..7b767e02c 100644 --- a/gajim/common/dbus/music_track.py +++ b/gajim/common/dbus/music_track.py @@ -22,8 +22,8 @@ from __future__ import annotations from typing import Any -from typing import cast from typing import Optional +from typing import TypedDict import logging import sys @@ -40,6 +40,12 @@ log = logging.getLogger('gajim.c.dbus.music_track') MPRIS_PLAYER_PREFIX = 'org.mpris.MediaPlayer2.' +class TrackProperties(TypedDict, total=False): + Metadata: dict[str, str] + PlaybackStatus: str + + + class MusicTrackListener: _instance: Optional[MusicTrackListener] = None @@ -175,8 +181,8 @@ class MusicTrackListener: self._get_playing_track(user_data[0]) @staticmethod - def _get_music_info(properties: dict[str, str]) -> Optional[TuneData]: - meta = cast(dict[str, str], properties.get('Metadata')) + def _get_music_info(properties: TrackProperties) -> Optional[TuneData]: + meta = properties.get('Metadata') if meta is None or not meta: return None diff --git a/gajim/common/events.py b/gajim/common/events.py index 307217b50..6dca97fe3 100644 --- a/gajim/common/events.py +++ b/gajim/common/events.py @@ -406,7 +406,7 @@ class MessageReceived(ApplicationEvent): unique_id: str stanza_id: str fjid: str - resource: str + resource: str | None delayed: Optional[float] msg_log_id: Optional[int] displaymarking: Optional[Displaymarking] diff --git a/gajim/common/filetransfer.py b/gajim/common/filetransfer.py index 53b2c605b..8c34d1bf2 100644 --- a/gajim/common/filetransfer.py +++ b/gajim/common/filetransfer.py @@ -61,8 +61,6 @@ class FileTransfer(Observable): self.update_progress() def get_state_description(self) -> str: - if self._state is None: - return '' return self._state_descriptions.get(self._state, '') def set_preparing(self) -> None: diff --git a/gajim/common/preview_helpers.py b/gajim/common/preview_helpers.py index 22d750000..6923d7d44 100644 --- a/gajim/common/preview_helpers.py +++ b/gajim/common/preview_helpers.py @@ -435,10 +435,11 @@ def get_previewable_mime_types() -> tuple[str, ...]: for fmt in GdkPixbuf.Pixbuf.get_formats(): for mime_type in fmt.get_mime_types(): previewable_mime_types.add(mime_type.lower()) - if Image is not None: - Image.init() - for mime_type in Image.MIME.values(): - previewable_mime_types.add(mime_type.lower()) + + Image.init() + for mime_type in Image.MIME.values(): + previewable_mime_types.add(mime_type.lower()) + return tuple(filter( lambda mime_type: mime_type.startswith('image'), previewable_mime_types diff --git a/gajim/common/storage/archive.py b/gajim/common/storage/archive.py index 45762156c..35c82eff5 100644 --- a/gajim/common/storage/archive.py +++ b/gajim/common/storage/archive.py @@ -106,7 +106,7 @@ class ConversationRow(NamedTuple): show: int message: str subject: str - additional_data: AdditionalDataDict + additional_data: AdditionalDataDict | None log_line_id: int message_id: str stanza_id: str @@ -118,8 +118,8 @@ class LastConversationRow(NamedTuple): contact_name: str time: float kind: int - message: str - additional_data: AdditionalDataDict + message: str | None + additional_data: AdditionalDataDict | None message_id: str stanza_id: str @@ -149,7 +149,7 @@ class MessageMetaRow(NamedTuple): class LastArchiveMessageRow(NamedTuple): id: int last_mam_id: str - oldest_mam_timestamp: str + oldest_mam_timestamp: str | None last_muc_timestamp: str @@ -404,7 +404,7 @@ class MessageArchiveStorage(SqliteStorage): def get_last_conversation_line(self, account: str, jid: JID - ) -> LastConversationRow: + ) -> LastConversationRow | None: ''' Load the last line of a conversation with jid for account. Loads messages, but no status messages or error messages. @@ -879,8 +879,8 @@ class MessageArchiveStorage(SqliteStorage): def find_stanza_id(self, account: str, archive_jid: str, - stanza_id: str, - origin_id: Optional[str] = None, + stanza_id: str | None, + origin_id: str | None = None, groupchat: bool = False ) -> bool: ''' diff --git a/gajim/common/storage/base.py b/gajim/common/storage/base.py index 62e4ecbfd..5b1a7c818 100644 --- a/gajim/common/storage/base.py +++ b/gajim/common/storage/base.py @@ -217,9 +217,7 @@ class SqliteStorage: return con def _reinit_storage(self) -> None: - if self._con is not None: - self._con.close() - + self._con.close() if self._path is not None: self._path.unlink() self.init() diff --git a/gajim/common/storage/cache.py b/gajim/common/storage/cache.py index 854d6ab61..e016a669d 100644 --- a/gajim/common/storage/cache.py +++ b/gajim/common/storage/cache.py @@ -353,7 +353,7 @@ class CacheStorage(SqliteStorage): return self._con.execute(sql).fetchall() @timeit - def get_unread_count(self, account: str, jid: JID) -> int: + def get_unread_count(self, account: str, jid: JID) -> int | None: sql = '''SELECT count, message_id, timestamp FROM unread WHERE account = ? AND jid = ?''' return self._con.execute(sql, (account, jid)).fetchone() diff --git a/gajim/gtk/account_side_bar.py b/gajim/gtk/account_side_bar.py index 607f050a8..e48620423 100644 --- a/gajim/gtk/account_side_bar.py +++ b/gajim/gtk/account_side_bar.py @@ -56,7 +56,7 @@ class AccountSideBar(Gtk.ListBox): app.window.show_account_page(row.account) def activate_account_page(self, account: str) -> None: - row = cast(Account, self.get_selected_row()) + row = cast(Account | None, self.get_selected_row()) if row is not None and row.account == account: return diff --git a/gajim/gtk/application.py b/gajim/gtk/application.py index 8e4162e73..ad40a119e 100644 --- a/gajim/gtk/application.py +++ b/gajim/gtk/application.py @@ -523,10 +523,10 @@ class GajimApplication(Gtk.Application, CoreApplication): username: str, domain: str, password: str, - proxy_name: str, + proxy_name: str | None, custom_host: tuple[str, ConnectionProtocol, - ConnectionType], + ConnectionType] | None, anonymous: bool = False ) -> None: @@ -544,7 +544,7 @@ class GajimApplication(Gtk.Application, CoreApplication): # Action must be added before account window is updated self.add_account_actions(account) - window = cast(AccountsWindow, get_app_window('AccountsWindow')) + window = cast(AccountsWindow | None, get_app_window('AccountsWindow')) if window is not None: window.add_account(account) @@ -552,7 +552,7 @@ class GajimApplication(Gtk.Application, CoreApplication): CoreApplication.enable_account(self, account) menus.build_accounts_menu() self.update_app_actions_state() - window = cast(AccountsWindow, get_app_window('AccountsWindow')) + window = cast(AccountsWindow | None, get_app_window('AccountsWindow')) if window is not None: window.enable_account(account, True) @@ -574,7 +574,7 @@ class GajimApplication(Gtk.Application, CoreApplication): self.remove_account_actions(account) - window = cast(AccountsWindow, get_app_window('AccountsWindow')) + window = cast(AccountsWindow | None, get_app_window('AccountsWindow')) if window is not None: window.remove_account(account) @@ -660,7 +660,7 @@ class GajimApplication(Gtk.Application, CoreApplication): def _on_add_contact_account_action(_action: Gio.SimpleAction, param: GLib.Variant) -> None: account, jid = param.get_strv() - if jid is not None: + if jid: jid = JID.from_string(jid) open_window('AddContact', account=account or None, jid=jid or None) @@ -822,9 +822,9 @@ class GajimApplication(Gtk.Application, CoreApplication): def _remove() -> None: app.storage.archive.remove_history(params.account, params.jid) control = app.window.get_control() - if params.jid is not None: - if not control.is_loaded(params.account, params.jid): - return + + if not control.is_loaded(params.account, params.jid): + return control.reset_view() diff --git a/gajim/gtk/avatar.py b/gajim/gtk/avatar.py index 2e084b861..9b93acca8 100644 --- a/gajim/gtk/avatar.py +++ b/gajim/gtk/avatar.py @@ -70,8 +70,7 @@ def generate_avatar(letters: str, color_r, color_g, color_b = color # Set up colors and size - if scale is not None: - size = size * scale + size = size * scale width = size height = size @@ -510,8 +509,6 @@ class AvatarStorage(metaclass=Singleton): returns SHA1 value of the avatar or None on error ''' - if data is None: - return None sha = hashlib.sha1(data).hexdigest() path = configpaths.get('AVATAR') / sha diff --git a/gajim/gtk/blocking.py b/gajim/gtk/blocking.py index e44fd81d4..2c358bfda 100644 --- a/gajim/gtk/blocking.py +++ b/gajim/gtk/blocking.py @@ -108,8 +108,6 @@ class BlockingList(Gtk.ApplicationWindow): def _on_remove(self, _button: Gtk.ToolButton) -> None: selected_rows = self._ui.block_view.get_selection().get_selected_rows() - if selected_rows is None: - return mod, paths = selected_rows for path in paths: iter_ = mod.get_iter(path) diff --git a/gajim/gtk/chat_list.py b/gajim/gtk/chat_list.py index d62274526..914a7197f 100644 --- a/gajim/gtk/chat_list.py +++ b/gajim/gtk/chat_list.py @@ -144,7 +144,7 @@ class ChatList(Gtk.ListBox, EventHelper): return None def get_selected_chat(self) -> Optional[ChatListRow]: - row = cast(ChatListRow, self.get_selected_row()) + row = cast(ChatListRow | None, self.get_selected_row()) if row is None: return None return row @@ -390,7 +390,7 @@ class ChatList(Gtk.ListBox, EventHelper): log.debug('Dropped row is not pinned') return - row = cast(ChatListRow, self.get_row_at_y(y_coord)) + row = cast(ChatListRow | None, self.get_row_at_y(y_coord)) if row is not None: alloc = row.get_allocation() hover_row_y = alloc.y @@ -455,7 +455,7 @@ class ChatList(Gtk.ListBox, EventHelper): return text in row.contact_name.lower() @staticmethod - def _header_func(row: ChatListRow, before: ChatListRow) -> None: + def _header_func(row: ChatListRow, before: ChatListRow | None) -> None: if before is None: if row.is_pinned: row.set_header_type(RowHeaderType.PINNED) diff --git a/gajim/gtk/chat_list_stack.py b/gajim/gtk/chat_list_stack.py index 64ff1b4fd..de9748d3b 100644 --- a/gajim/gtk/chat_list_stack.py +++ b/gajim/gtk/chat_list_stack.py @@ -98,8 +98,7 @@ class ChatListStack(Gtk.Stack, EventHelper): for action in actions: action_name, variant, func = action - if variant is not None: - variant = GLib.VariantType.new(variant) + variant = GLib.VariantType.new(variant) act = Gio.SimpleAction.new(action_name, variant) act.connect('activate', func) app.window.add_action(act) diff --git a/gajim/gtk/control.py b/gajim/gtk/control.py index c5d0520cb..d71040ca8 100644 --- a/gajim/gtk/control.py +++ b/gajim/gtk/control.py @@ -703,6 +703,7 @@ class ChatControl(EventHelper): for msg in messages: if msg.kind in (KindConstant.FILE_TRANSFER_INCOMING, KindConstant.FILE_TRANSFER_OUTGOING): + assert msg.additional_data is not None if msg.additional_data.get_value('gajim', 'type') == 'jingle': self._scrolled_view.add_jingle_file_transfer( db_message=msg) diff --git a/gajim/gtk/conversation/message_widget.py b/gajim/gtk/conversation/message_widget.py index 4a83505c3..46f9629f9 100644 --- a/gajim/gtk/conversation/message_widget.py +++ b/gajim/gtk/conversation/message_widget.py @@ -14,7 +14,6 @@ from __future__ import annotations -from typing import cast from typing import Optional from typing import Union @@ -42,10 +41,10 @@ class MessageWidget(Gtk.Box): self._account = account self._selectable = selectable - self._content = cast(ContentT, None) + self._content: ContentT | None = None self._action_phrase_text = '' - def get_content(self) -> ContentT: + def get_content(self) -> ContentT | None: return self._content def get_text(self) -> str: diff --git a/gajim/gtk/conversation/rows/call.py b/gajim/gtk/conversation/rows/call.py index ce9d57ad4..8e899cabc 100644 --- a/gajim/gtk/conversation/rows/call.py +++ b/gajim/gtk/conversation/rows/call.py @@ -64,6 +64,7 @@ class CallRow(BaseRow): self._session: Optional[JingleSession] = None if db_message is not None: + assert db_message.additional_data is not None sid = db_message.additional_data.get_value('gajim', 'sid') module = self._client.get_module('Jingle') self._session = module.get_jingle_session(self._contact.jid, sid) @@ -127,11 +128,10 @@ class CallRow(BaseRow): is_self = False if self._event is not None: - if self._event is not None: - is_self = False - else: - contact = self._contact - is_self = True + is_self = False + else: + contact = self._contact + is_self = True scale = self.get_scale_factor() avatar = contact.get_avatar(AvatarSize.ROSTER, scale, add_show=False) diff --git a/gajim/gtk/conversation/rows/file_transfer_jingle.py b/gajim/gtk/conversation/rows/file_transfer_jingle.py index bcd45db60..9835d902f 100644 --- a/gajim/gtk/conversation/rows/file_transfer_jingle.py +++ b/gajim/gtk/conversation/rows/file_transfer_jingle.py @@ -80,6 +80,7 @@ class FileTransferJingleRow(BaseRow): self._contact = contact if db_message is not None: + assert db_message.additional_data is not None sid = db_message.additional_data.get_value('gajim', 'sid') assert sid is not None self._file_props = FilesProp.getFilePropBySid(sid) diff --git a/gajim/gtk/conversation/rows/message.py b/gajim/gtk/conversation/rows/message.py index 7211efb53..0e5ec9954 100644 --- a/gajim/gtk/conversation/rows/message.py +++ b/gajim/gtk/conversation/rows/message.py @@ -94,7 +94,7 @@ class MessageRow(BaseRow): self._contact = contact self._is_groupchat: bool = False - if contact is not None and contact.is_groupchat: + if contact.is_groupchat: self._is_groupchat = True self._has_receipt: bool = marker == 'received' @@ -257,9 +257,6 @@ class MessageRow(BaseRow): 'gajim-mention-highlight') def _get_avatar(self, kind: str, name: str) -> Optional[cairo.ImageSurface]: - if self._contact is None: - return None - scale = self.get_scale_factor() if isinstance(self._contact, GroupchatContact): contact = self._contact.get_resource(name) diff --git a/gajim/gtk/conversation/view.py b/gajim/gtk/conversation/view.py index 8a619dfc4..5a2747eab 100644 --- a/gajim/gtk/conversation/view.py +++ b/gajim/gtk/conversation/view.py @@ -372,7 +372,9 @@ class ConversationView(Gtk.ScrolledWindow): return self._contact def _get_row_at_index(self, index: int) -> BaseRow: - return cast(BaseRow, self._list_box.get_row_at_index(index)) + row = self._list_box.get_row_at_index(index) + assert row is not None + return cast(BaseRow, row) def get_first_message_row(self) -> Optional[MessageRow]: for row in self._list_box.get_children(): @@ -555,7 +557,7 @@ class ConversationView(Gtk.ScrolledWindow): self._active_date_rows.add(start_of_day) self._list_box.add(date_row) - row = self._get_row_at_index(date_row.get_index() + 1) + row = self._list_box.get_row_at_index(date_row.get_index() + 1) if row is None: return @@ -582,7 +584,7 @@ class ConversationView(Gtk.ScrolledWindow): index = message.get_index() while index != 0: index -= 1 - row = self._get_row_at_index(index) + row = self._list_box.get_row_at_index(index) if row is None: return None @@ -603,7 +605,7 @@ class ConversationView(Gtk.ScrolledWindow): index = message.get_index() while True: index += 1 - row = self._get_row_at_index(index) + row = self._list_box.get_row_at_index(index) if row is None: return @@ -713,9 +715,6 @@ class ConversationView(Gtk.ScrolledWindow): row.update() def set_read_marker(self, id_: str) -> None: - if id_ is None: - return - row = self._get_row_by_message_id(id_) if row is None: return diff --git a/gajim/gtk/dialogs.py b/gajim/gtk/dialogs.py index c3d92b683..0bc0c02fd 100644 --- a/gajim/gtk/dialogs.py +++ b/gajim/gtk/dialogs.py @@ -37,7 +37,7 @@ class DialogButton(NamedTuple): callback: Any args: Any kwargs: Any - action: ButtonAction + action: ButtonAction | None is_default: bool @classmethod diff --git a/gajim/gtk/groupchat_inviter.py b/gajim/gtk/groupchat_inviter.py index 46bf95e13..081ea1d1e 100644 --- a/gajim/gtk/groupchat_inviter.py +++ b/gajim/gtk/groupchat_inviter.py @@ -69,9 +69,6 @@ class ContactRow(Gtk.ListBoxRow): box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) box.set_hexpand(True) - if self._name is None: - self._name = _('Invite New Contact') - self._name_label = Gtk.Label(label=self._name) self._name_label.set_ellipsize(Pango.EllipsizeMode.END) self._name_label.set_xalign(0) diff --git a/gajim/gtk/groupchat_roster.py b/gajim/gtk/groupchat_roster.py index 938531265..cc1313092 100644 --- a/gajim/gtk/groupchat_roster.py +++ b/gajim/gtk/groupchat_roster.py @@ -557,10 +557,7 @@ class GroupchatRoster(Gtk.Revealer, EventHelper): name = f'<span strikethrough="true">{name}</span>' # add status msg, if not empty, under contact name - status = contact.status - if status is not None: - status = status.strip() - + status = contact.status.strip() if status and app.settings.get('show_status_msgs_in_roster'): # Display only first line status = status.split('\n', 1)[0] diff --git a/gajim/gtk/history_export.py b/gajim/gtk/history_export.py index 8e2476ab8..ce615dcd4 100644 --- a/gajim/gtk/history_export.py +++ b/gajim/gtk/history_export.py @@ -203,9 +203,7 @@ class SelectAccountDir(Page): self._set_complete() def _set_complete(self) -> None: - self.complete = bool( - self._account is not None and - self._export_directory is not None) + self.complete = bool(self._account is not None) self.update_page_complete() def _on_file_set(self, button: Gtk.FileChooserButton) -> None: diff --git a/gajim/gtk/history_sync.py b/gajim/gtk/history_sync.py index 801058d3e..32f6f410f 100644 --- a/gajim/gtk/history_sync.py +++ b/gajim/gtk/history_sync.py @@ -251,7 +251,7 @@ class SelectTime(Page): def _on_row_selected(self, _listbox: Gtk.ListBox, row: TimeOption) -> None: self._timedelta = row.get_timedelta() - self.complete = row is not None + self.complete = True self.update_page_complete() def get_timedelta(self) -> Optional[timedelta]: diff --git a/gajim/gtk/main.py b/gajim/gtk/main.py index 3ae454548..92b256364 100644 --- a/gajim/gtk/main.py +++ b/gajim/gtk/main.py @@ -769,7 +769,7 @@ class MainWindow(Gtk.ApplicationWindow, EventHelper): param: GLib.Variant) -> None: workspace_id = param.get_string() - if workspace_id is not None: + if workspace_id: self.add_workspace(workspace_id) def add_workspace(self, @@ -860,7 +860,7 @@ class MainWindow(Gtk.ApplicationWindow, EventHelper): param: GLib.Variant) -> None: workspace_id = param.get_string() - if workspace_id is not None: + if workspace_id: self.activate_workspace(workspace_id) def activate_workspace(self, workspace_id: str) -> None: diff --git a/gajim/gtk/message_input.py b/gajim/gtk/message_input.py index aa9f4ddd8..afdaf8af1 100644 --- a/gajim/gtk/message_input.py +++ b/gajim/gtk/message_input.py @@ -138,7 +138,7 @@ class MessageInputTextView(Gtk.TextView, EventHelper): message_row = app.storage.archive.get_last_correctable_message( self._contact.account, self._contact.jid, last_message_id) - if message_row is None: + if message_row is None or message_row.message is None: return self._set_correcting(True) diff --git a/gajim/gtk/notification.py b/gajim/gtk/notification.py index 41d6db11c..56e36d843 100644 --- a/gajim/gtk/notification.py +++ b/gajim/gtk/notification.py @@ -321,8 +321,7 @@ class Linux(NotificationBackend): return notification = Gio.Notification() - if event.title is not None: - notification.set_title(event.title) + notification.set_title(event.title) text = event.text if 'body-markup' in self._caps: diff --git a/gajim/gtk/preview_audio.py b/gajim/gtk/preview_audio.py index f1ee1cd66..5c870bbf0 100644 --- a/gajim/gtk/preview_audio.py +++ b/gajim/gtk/preview_audio.py @@ -605,8 +605,7 @@ class AudioWidget(Gtk.Box): if self._audio_analyzer is not None: self._audio_analyzer.destroy() - if self._ui.speed_popover is not None: - self._ui.speed_popover.destroy() + self._ui.speed_popover.destroy() self._remove_seek_bar_update_idle() diff --git a/gajim/gtk/profile.py b/gajim/gtk/profile.py index 91eecdbc9..d0c9ff088 100644 --- a/gajim/gtk/profile.py +++ b/gajim/gtk/profile.py @@ -175,9 +175,6 @@ class ProfileWindow(Gtk.ApplicationWindow): log.info('Error loading VCard: %s', error) self._current_vcard = VCard() - if self._current_vcard is None: - self._current_vcard = VCard() - self._load_avatar() self._vcard_grid.set_vcard(self._current_vcard.copy()) self._ui.profile_stack.set_visible_child_name('profile') diff --git a/gajim/gtk/resource_selector.py b/gajim/gtk/resource_selector.py index 008e3d457..d46501521 100644 --- a/gajim/gtk/resource_selector.py +++ b/gajim/gtk/resource_selector.py @@ -75,7 +75,7 @@ class ResourceSelector(Gtk.ScrolledWindow): def _on_row_selected(self, _listbox: Gtk.ListBox, - row: ResourceRow + row: ResourceRow | None ) -> None: state = bool(row is not None) self.emit('selection-changed', state) diff --git a/gajim/gtk/search_view.py b/gajim/gtk/search_view.py index 1b6d9a458..c988d9e42 100644 --- a/gajim/gtk/search_view.py +++ b/gajim/gtk/search_view.py @@ -83,7 +83,7 @@ class SearchView(Gtk.Box): self._clear() @staticmethod - def _header_func(row: ResultRow, before: ResultRow) -> None: + def _header_func(row: ResultRow, before: ResultRow | None) -> None: if before is None: row.set_header(RowHeader(row.account, row.jid, row.time)) else: diff --git a/gajim/gtk/util.py b/gajim/gtk/util.py index 40f066df2..44b674ac7 100644 --- a/gajim/gtk/util.py +++ b/gajim/gtk/util.py @@ -260,7 +260,9 @@ def get_cursor(name: str) -> Gdk.Cursor: cursor = Gdk.Cursor.new_from_name(display, name) if cursor is not None: return cursor - return Gdk.Cursor.new_from_name(display, 'default') + cursor = Gdk.Cursor.new_from_name(display, 'default') + assert cursor is not None + return cursor def scroll_to_end(widget: Gtk.ScrolledWindow) -> bool: @@ -273,7 +275,7 @@ def scroll_to_end(widget: Gtk.ScrolledWindow) -> bool: bool: The return value is False so it can be used with GLib.idle_add. ''' adj_v = widget.get_vadjustment() - if adj_v is None: + if adj_v is None: # pyright: ignore # This can happen when the Widget is already destroyed when called # from GLib.idle_add return False diff --git a/gajim/gtk/workspace_side_bar.py b/gajim/gtk/workspace_side_bar.py index 88b0ca9ee..f4790b2ad 100644 --- a/gajim/gtk/workspace_side_bar.py +++ b/gajim/gtk/workspace_side_bar.py @@ -239,7 +239,7 @@ class WorkspaceSideBar(Gtk.ListBox): return None def activate_workspace(self, workspace_id: str) -> None: - row = cast(CommonWorkspace, self.get_selected_row()) + row = cast(CommonWorkspace | None, self.get_selected_row()) if row is not None and row.workspace_id == workspace_id: return @@ -247,12 +247,12 @@ class WorkspaceSideBar(Gtk.ListBox): self.select_row(row) def activate_workspace_number(self, number: int) -> None: - row = cast(CommonWorkspace, self.get_row_at_index(number)) + row = cast(CommonWorkspace | None, self.get_row_at_index(number)) if row is not None and row.workspace_id != 'add': app.window.activate_workspace(row.workspace_id) def get_active_workspace(self) -> Optional[str]: - row = cast(CommonWorkspace, self.get_selected_row()) + row = cast(CommonWorkspace | None, self.get_selected_row()) if row is None: return None return row.workspace_id diff --git a/gajim/gtk/xml_console.py b/gajim/gtk/xml_console.py index 0811c4c94..351432d8a 100644 --- a/gajim/gtk/xml_console.py +++ b/gajim/gtk/xml_console.py @@ -257,7 +257,7 @@ class XMLConsoleWindow(Gtk.ApplicationWindow, EventHelper): def _on_paste_last(self, *args: Any) -> None: buffer_ = self._ui.input_entry.get_buffer() - if buffer_ is not None and self.last_stanza is not None: + if self.last_stanza is not None: buffer_.set_text(self.last_stanza) self._ui.input_entry.grab_focus() |