Skip to content

Commit

Permalink
Apply simple Ruff fixes
Browse files Browse the repository at this point in the history
Relates to #237

With one exception, this is the output of `ruff lint --fix`. The changes
look minor - it mostly removes unused imports.

Ruff reports a lot of other errors, including a fair amount of
"Undefined name" that indicate broken code paths. We can tackle those
separately, and decide whether we want to add Ruff to the pre-commit
hook.

This commit in itself is still a good quality of life improvement.

I also did some smoke testing to make sure nothing is obviously broken.
  • Loading branch information
SqAtx committed May 25, 2024
1 parent 28c472f commit 68e735b
Show file tree
Hide file tree
Showing 27 changed files with 23 additions and 42 deletions.
2 changes: 1 addition & 1 deletion GTG/backends/generic_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def cast_param_type_from_string(cls, param_value, param_type):
the_list = [the_list]
return the_list
else:
raise NotImplemented(f"I don't know what type is '{param_type}'")
raise NotImplementedError(f"I don't know what type is '{param_type}'")

def cast_param_type_to_string(self, param_type, param_value):
"""
Expand Down
6 changes: 3 additions & 3 deletions GTG/core/base_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self) -> None:
# --------------------------------------------------------------------------

def new(self) -> Any:
raise NotImplemented
raise NotImplementedError


def get(self, key: UUID) -> Any:
Expand Down Expand Up @@ -170,11 +170,11 @@ def unparent(self, item_id: UUID, parent_id: UUID) -> None:
# --------------------------------------------------------------------------

def from_xml(self, xml: Element) -> Any:
raise NotImplemented
raise NotImplementedError


def to_xml(self) -> Element:
raise NotImplemented
raise NotImplementedError


# --------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion GTG/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def get(self, option):
if value is None and default_value is None:
raise ValueError(
'No valid configuration value or default value was '
'found for %s in %s'.format(option, self._section_name))
f'found for {option} in {self._section_name}')
elif value is None:
return default_value
else:
Expand Down
2 changes: 1 addition & 1 deletion GTG/core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

"""Filters for tags and tasks"""

from gi.repository import Gtk, GObject, Gdk
from gi.repository import Gtk
from GTG.core.tags import Tag
from GTG.core.tasks import Task, Status
from GTG.core import search
Expand Down
2 changes: 1 addition & 1 deletion GTG/core/sorters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

"""Sorters for tags and tasks."""

from gi.repository import Gtk, GObject, Gdk
from gi.repository import Gtk
from GTG.core.tasks import Task

def unwrap(row, expected_type):
Expand Down
2 changes: 0 additions & 2 deletions GTG/core/system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# this program. If not, see <http://www.gnu.org/licenses/>.


from datetime import date
import gi
import os
import platform
import importlib
Expand Down
1 change: 0 additions & 1 deletion GTG/core/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from lxml import etree as et
from GTG.core.dates import Date
from GTG.core.dirs import DATA_DIR
from uuid import uuid4, UUID

from datetime import date
from typing import Optional, Tuple
Expand Down
4 changes: 2 additions & 2 deletions GTG/gtk/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def do_activate(self):
self.browser.restore_editor_windows()

log.debug("Application activation finished")
except Exception as e:
except Exception:
log.exception("Exception during activation")
dialog = do_error_dialog(self._exception, "Activation", ignorable=False)
dialog.set_application(self) # Keep application alive to show it
Expand Down Expand Up @@ -185,7 +185,7 @@ def do_open(self, files, n_files, hint):
log.info("Unknown task to open: %s", file.get_uri())

log.debug("Application opening finished")
except Exception as e:
except Exception:
log.exception("Exception during opening")
dialog = do_error_dialog(self._exception, "Opening", ignorable=False)
dialog.set_application(self) # Keep application alive to show it
Expand Down
2 changes: 1 addition & 1 deletion GTG/gtk/backends/backendstree.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from gi.repository import Gtk

from GTG.gtk.colors import get_colored_tags_markup, rgba_to_hex
from GTG.gtk.colors import get_colored_tags_markup
from GTG.backends.backend_signals import BackendSignals

ALLTASKS_TAG = 'gtg-tags-all'
Expand Down
1 change: 0 additions & 1 deletion GTG/gtk/browser/delete_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from gi.repository import Gtk

from gettext import gettext as _, ngettext
from GTG.gtk import ViewConfig


class DeletionUI:
Expand Down
2 changes: 0 additions & 2 deletions GTG/gtk/browser/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from GTG.core.system_info import SystemInfo
from GTG.backends.backend_signals import BackendSignals
from GTG.core.dirs import ICONS_DIR
from GTG.core.search import parse_search_query, InvalidQuery
from gettext import gettext as _
from GTG.gtk.browser import GnomeConfig
from GTG.gtk.browser import quick_add
Expand All @@ -45,7 +44,6 @@
from GTG.gtk.tag_completion import TagCompletion
from GTG.core.dates import Date
from GTG.core.tasks import Filter, Status, Task
from GTG.gtk.browser.adaptive_button import AdaptiveFittingWidget # Register type

log = logging.getLogger(__name__)
PANE_STACK_NAMES_MAP = {
Expand Down
3 changes: 1 addition & 2 deletions GTG/gtk/browser/search_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
This module contains the SearchEditor class which is a window that allows the
user to edit a saved search properties.
"""
from gi.repository import GObject, Gtk, Gdk, GdkPixbuf, GLib
from gi.repository import GObject, Gtk, GLib

import logging
import random
from gettext import gettext as _
from GTG.gtk.browser import GnomeConfig

Expand Down
1 change: 0 additions & 1 deletion GTG/gtk/browser/sidebar_context_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from gi.repository import Gtk, Gio

from gettext import gettext as _
from GTG.gtk.colors import generate_tag_color, color_add, color_remove
from GTG.gtk.browser import GnomeConfig


Expand Down
5 changes: 2 additions & 3 deletions GTG/gtk/browser/tag_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
This module contains the TagEditor class which is a window that allows the
user to edit a tag properties.
"""
from gi.repository import GObject, Gtk, Gdk, GdkPixbuf, GLib
from gi.repository import GObject, Gtk, Gdk, GLib

import logging
import random
from gettext import gettext as _
from GTG.gtk.colors import color_add, color_remove, RGBA, rgb_to_hex, random_color
from GTG.gtk.colors import color_add, color_remove, rgb_to_hex
from GTG.gtk.browser import GnomeConfig

log = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion GTG/gtk/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------

from gi.repository import Gdk, Gtk
from gi.repository import Gdk
from functools import reduce
import random

Expand Down
2 changes: 1 addition & 1 deletion GTG/gtk/editor/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import datetime

from gi.repository import GObject, GLib, Gdk, Gtk
from gi.repository import GObject, GLib, Gtk

from GTG.gtk.editor import GnomeConfig
from GTG.core.dates import Date
Expand Down
7 changes: 3 additions & 4 deletions GTG/gtk/editor/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@
import time
from gettext import gettext as _, ngettext

from gi.repository import Gdk, Gtk, GLib, Pango
from gi.repository import Gdk, Gtk, GLib
from gi.repository.GObject import signal_handler_block
from GTG.core.dates import Accuracy, Date
from GTG.core.dates import Date
from GTG.core.dirs import UI_DIR
from GTG.core.plugins.api import PluginAPI
from GTG.core.plugins.engine import PluginEngine
from GTG.gtk.editor import GnomeConfig
from GTG.gtk.editor.calendar import GTGCalendar
from GTG.gtk.editor.recurring_menu import RecurringMenu
from GTG.gtk.editor.taskview import TaskView
from GTG.gtk.tag_completion import tag_filter
from GTG.gtk.colors import rgb_to_hex
from GTG.core.tasks import Task, Status, DEFAULT_TITLE

Expand Down Expand Up @@ -430,7 +429,7 @@ def init_dimensions(self):
if size:
try:
self.set_default_size(int(size[0]), int(size[1]))
except ValueError as e:
except ValueError:
log.warning('Invalid size configuration for task %s: %s',
self.task.id, size)

Expand Down
5 changes: 1 addition & 4 deletions GTG/gtk/errorhandler.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@

from gi.repository import GObject, GLib, Gtk
from gi.repository import GObject, Gtk
from gettext import gettext as _
from typing import Optional
import traceback
import sys
import os
import platform
import functools
import enum
import logging
import configparser

from GTG.core import info
from GTG.core.system_info import SystemInfo
Expand Down
2 changes: 1 addition & 1 deletion GTG/gtk/general_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import os

from gi.repository import Gtk, Gdk, GLib
from gi.repository import Gtk, GLib

from GTG.core.dirs import UI_DIR
from gettext import gettext as _
Expand Down
1 change: 0 additions & 1 deletion GTG/gtk/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from gi.repository import Gtk, Pango

from GTG.core import info
from GTG.core.plugins import GnomeConfig
from GTG.core.plugins.engine import PluginEngine
from gettext import gettext as _
Expand Down
2 changes: 1 addition & 1 deletion GTG/plugins/export/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from GTG.core.dirs import plugin_configuration_dir

from Cheetah.Template import Template as CheetahTemplate
from gi.repository import GObject, GLib
from gi.repository import GLib

TEMPLATE_PATHS = [
os.path.join(plugin_configuration_dir('export'), "export_templates"),
Expand Down
1 change: 0 additions & 1 deletion GTG/plugins/gamify/gamify.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from collections import defaultdict
import logging

from gi.repository import Gio
from gi.repository import Gtk

from gettext import gettext as _
Expand Down
1 change: 0 additions & 1 deletion GTG/plugins/send_email/sendEmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""

from gi.repository import Gio
from gi.repository import Gtk
import urllib.request
import urllib.parse
import urllib.error
Expand Down
2 changes: 1 addition & 1 deletion GTG/plugins/unmaintained/bugzilla/bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.

from gi.repository import GObject, GLib
from gi.repository import GLib
import re
import threading
import xmlrpc.client
Expand Down
3 changes: 1 addition & 2 deletions tests/core/test_tag_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
# -----------------------------------------------------------------------------

from unittest import TestCase
from uuid import uuid4

from GTG.core.tags import Tag, TagStore
from lxml.etree import Element, SubElement, XML
from lxml.etree import XML


class TestTagStore(TestCase):
Expand Down
1 change: 0 additions & 1 deletion tests/core/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------

import unittest
from unittest import TestCase
from uuid import uuid4

Expand Down
1 change: 0 additions & 1 deletion tests/tools/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------

import unittest
from unittest import TestCase

from GTG.core.tags import extract_tags_from_text
Expand Down

0 comments on commit 68e735b

Please sign in to comment.