Skip to content

Commit

Permalink
More Ruff fixes
Browse files Browse the repository at this point in the history
Relates to #237
This is a follow-up to c2f650f

I ran `ruff check` and looked at the errors that Ruff finds but doesn't
want to fix automatically.

There are still 13 errors, which all seem to indicate a bug. They are
mostly "Undefined name". I will fix them individually.
  • Loading branch information
SqAtx authored and diegogangl committed Jul 17, 2024
1 parent c35516e commit ee101cc
Show file tree
Hide file tree
Showing 21 changed files with 37 additions and 51 deletions.
2 changes: 1 addition & 1 deletion GTG/core/base_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import logging

from lxml.etree import _Element
from typing import Any, Dict, List, Optional, TypeVar, Generic, Protocol
from typing import Dict, List, Optional, TypeVar, Generic, Protocol


log = logging.getLogger(__name__)
Expand Down
1 change: 0 additions & 1 deletion GTG/core/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def copy(self, start, stop, bullet=None):
if hasattr(ta, 'is_subtask'):
is_subtask = True
tid = ta.child
tas = self.ds.tasks.lookup[tid]
self.content.append(['subtask', tid])
if not is_subtask:
if end_line.get_line() < stop.get_line():
Expand Down
4 changes: 2 additions & 2 deletions GTG/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ def _type_function(self, default_value):
default_type = type(default_value)
if default_type in (list, tuple):
return self._getlist
elif default_type == int:
elif default_type is int:
return self._section.getint
elif default_type == bool:
elif default_type is bool:
return self._section.getboolean
else:
return self._section.get
Expand Down
11 changes: 7 additions & 4 deletions GTG/core/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import re

from lxml.etree import Element, SubElement, _Element
from typing import Any, Dict, List, Set, Optional
from typing import Dict, List, Set, Optional

from GTG.core.base_store import BaseStore

Expand Down Expand Up @@ -379,7 +379,8 @@ def add(self, item: Tag, parent_id: Optional[UUID] = None) -> None:
self.model.append(item)

self.emit('added', item)
if parent_id: self.lookup[parent_id].notify('children_count')
if parent_id:
self.lookup[parent_id].notify('children_count')


def parent(self, item_id: UUID, parent_id: UUID) -> None:
Expand All @@ -388,7 +389,8 @@ def parent(self, item_id: UUID, parent_id: UUID) -> None:
item = self.lookup[item_id]
pos = self.model.find(item)
self.model.remove(pos[1])
if parent_id: self.lookup[parent_id].notify('children_count')
if parent_id:
self.lookup[parent_id].notify('children_count')



Expand All @@ -397,4 +399,5 @@ def unparent(self, item_id: UUID, parent_id: UUID) -> None:
super().unparent(item_id, parent_id)
item = self.lookup[item_id]
self.model.append(item)
if parent_id: self.lookup[parent_id].notify('children_count')
if parent_id:
self.lookup[parent_id].notify('children_count')
6 changes: 4 additions & 2 deletions GTG/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,8 @@ def _remove_from_parent_model(self,task_id: UUID) -> None:
return
model = self.tid_to_subtask_model[item.parent.id]
pos = model.find(item)
if pos[0]: model.remove(pos[1])
if pos[0]:
model.remove(pos[1])


def _append_to_parent_model(self,task_id: UUID) -> None:
Expand All @@ -950,7 +951,8 @@ def _append_to_parent_model(self,task_id: UUID) -> None:
return
model = self.tid_to_subtask_model[item.parent.id]
pos = model.find(item)
if not pos[0]: model.append(item)
if not pos[0]:
model.append(item)


def add(self, item: Any, parent_id: Optional[UUID] = None) -> None:
Expand Down
2 changes: 0 additions & 2 deletions GTG/gtk/backends/parameters_ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
server and client
"""

import functools

from gi.repository import Gtk

from GTG.backends.generic_backend import GenericBackend
Expand Down
4 changes: 2 additions & 2 deletions GTG/gtk/browser/adaptive_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class ChildItem:
"""The natural height the widget claims to have"""

def __init__(self, *args, **kwargs):
self._children: List[ChildItem] = []
self._children: List[self.ChildItem] = []
"""Child widgets to consider together with internal bookkeeping data"""

self._child_to_draw: Optional[ChildItem] = None
self._child_to_draw: Optional[self.ChildItem] = None
"""Current child to draw"""

self._draw_smallest_child_if_smaller: bool = True
Expand Down
1 change: 0 additions & 1 deletion GTG/gtk/browser/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,6 @@ def on_tag_treeview_key_press_event(self, controller, keyval, keycode, state):
selected_tag = self.req.get_tag(selected_tags[0])
self.tagpopup.set_tag(selected_tag)
model, titer = self.tagtreeview.get_selection().get_selected()
rect = self.tagtreeview.get_cell_area(model.get_path(titer), None)
self.show_popup_at_tree_cursor(self.tagpopup, self.tagtreeview)
else:
self.reset_cursor()
Expand Down
4 changes: 3 additions & 1 deletion GTG/gtk/browser/task_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
from gi.repository import Gtk, GObject, Gdk, Gio, Pango
from GTG.core.tasks import Task, Status
from GTG.core.filters import TaskPaneFilter, SearchTaskFilter
from GTG.core.sorters import *
from GTG.core.sorters import (TaskAddedSorter, TaskDueSorter,
TaskModifiedSorter, TaskStartSorter,
TaskTagSorter, TaskTitleSorter)
from GTG.gtk.browser.tag_pill import TagPill
from gettext import gettext as _

Expand Down
9 changes: 3 additions & 6 deletions GTG/gtk/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,12 @@ def get_colored_tags_markup(ds, tag_names):

def generate_tag_color():

maxvalue = 1.0
flag = 0
while(flag == 0):
while True:
rgba = random_color()
my_color = rgb_to_hex(rgba)
if my_color not in used_color:
flag = 1
used_color.append(my_color)
return my_color
used_color.append(my_color)
return my_color


def grgba_to_hex(rgba, ignore_alpha=True):
Expand Down
1 change: 0 additions & 1 deletion GTG/gtk/editor/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def show(self):
self.__is_user_just_browsing_the_calendar = False

def __focus_out(self, g=None, s=None):
w = g.get_widget()
# We should only close if the pointer click is out of the calendar !
p = self.__window.get_window().get_pointer()
s = self.__window.get_size()
Expand Down
2 changes: 1 addition & 1 deletion GTG/gtk/editor/recurring_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, editor, task):
('recurr_year_today', self._on_recurr_year_today, None),
]:
# is property action (property name instead of callback)
if type(action_disc[1]) == str:
if isinstance(action_disc[1], str):
self.install_property_action('.'.join([prefix, action_disc[0]]), action_disc[1])
else:
self.install_action('.'.join([prefix, action_disc[0]]), action_disc[2], action_disc[1])
Expand Down
4 changes: 2 additions & 2 deletions GTG/gtk/errorhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def context_info(self):
return self._context_info

@context_info.setter
def context_info(self, info, refresh: bool = True):
self._context_info = str(info) if info != None else None
def context_info(self, context_info, refresh: bool = True):
self._context_info = str(context_info) if context_info is not None else None
if refresh:
self._update_additional_info()

Expand Down
2 changes: 1 addition & 1 deletion GTG/plugins/gamify/gamify.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def activate(self, plugin_api):
# Init the preference dialog
try:
self.pref_dialog = GamifyPreferences(self, self.plugin_api)
except:
except Exception:
self.configureable = False
log.debug('Cannot load preference dialog widget')

Expand Down
2 changes: 1 addition & 1 deletion GTG/plugins/unmaintained/tomboy/tomboy.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def onTaskClosed(self, plugin_api):
iter_start = self.textview.buff.get_iter_at_child_anchor(anchor)
iter_end = iter_start.copy()
iter_end.forward_char()
if type(widgets) == list and len(widgets) != 0:
if isinstance(widgets, list) and len(widgets) != 0:
# the anchor still contains a widget.
widget = widgets[0]
self.textview.buff.delete(iter_start, iter_end)
Expand Down
1 change: 0 additions & 1 deletion scripts/anonymize_task_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def anonymize(filename, outputfile):

for task in tasks:
textnode = task.getElementsByTagName("title")[0].childNodes[0]
nodevalue = textnode.nodeValue
replaced_title = re.sub('[^ \n\t]', 'm', textnode.nodeValue)
textnode.nodeValue = "%s %s" % (task.getAttribute('id'),
replaced_title)
Expand Down
2 changes: 2 additions & 0 deletions tests/core/test_quickadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def test_start(self):
self.assertEqual(expected1, parse(text1))
self.assertEqual(expected1, parse(text2))
self.assertEqual(expected1, parse(text3))
self.assertEqual(expected2, parse(text4))
self.assertEqual(expected3, parse(text5))


Expand Down Expand Up @@ -186,6 +187,7 @@ def test_due(self):
self.assertEqual(expected1, parse(text1))
self.assertEqual(expected1, parse(text2))
self.assertEqual(expected1, parse(text3))
self.assertEqual(expected2, parse(text4))
self.assertEqual(expected3, parse(text5))


Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_saved_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def test_xml_load_tree(self):
def test_xml_write_simple(self):

store = SavedSearchStore()
search1 = store.add(SavedSearch(uuid4(), 'Some @tag', 'Looking for some tag'))
search2 = store.add(SavedSearch(uuid4(), 'Some @other @tag', 'Looking for more'))
store.add(SavedSearch(uuid4(), 'Some @tag', 'Looking for some tag'))
store.add(SavedSearch(uuid4(), 'Some @other @tag', 'Looking for more'))

xml_root = store.to_xml()

Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_tag_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_xml_load_bad(self):

def test_xml_write_simple(self):
store = TagStore()
tag = store.new('My_tag')
store.new('My_tag')
tag2 = store.new('My_tag2')
tag3 = store.new('My_tag3', tag2.id)

Expand All @@ -95,7 +95,7 @@ def test_xml_write_simple(self):

def test_xml_write_tree(self):
store = TagStore()
tag = store.new('My_tag')
store.new('My_tag')
tag2 = store.new('My_tag2')
tag3 = store.new('My_tag3', tag2.id)

Expand Down
20 changes: 4 additions & 16 deletions tests/core/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def test_new_tree(self):
store = TaskStore()

root_task = store.new('My Root Task')
child_task = store.new('My Child Task', root_task.id)
store.new('My Child Task', root_task.id)

self.assertEqual(store.count(), 2)
self.assertEqual(store.count(root_only=True), 1)
Expand Down Expand Up @@ -570,7 +570,7 @@ def test_filter_tag(self):
task1 = task_store.new('My Task')
task2 = task_store.new('My Other Task')
task3 = task_store.new('My Other Other Task')
task4 = task_store.new('My Other Other Other Task')
task_store.new('My Other Other Other Task')

tag1 = Tag(id=uuid4(), name='A Tag')
tag2 = Tag(id=uuid4(), name='Another Tag')
Expand Down Expand Up @@ -599,7 +599,7 @@ def test_filter_tag(self):
def test_filter_custom(self):
task_store = TaskStore()

task1 = task_store.new('My Task')
task_store.new('My Task')
task2 = task_store.new('My Other Task')

filtered = task_store.filter_custom('title', lambda t: 'Other' in t)
Expand Down Expand Up @@ -643,18 +643,6 @@ def test_simple_reverse_sort(self):
self.assertEqual(task_store.data, expected)


def test_simple_reverse_sort(self):
task_store = TaskStore()

task1 = task_store.new('1. My Task')
task2 = task_store.new('2. My Other Task')

# Simple sort
task_store.sort(key='title',reverse=True)
expected = [task2, task1]
self.assertEqual(task_store.data, expected)


def test_nested_sort(self):
task_store = TaskStore()

Expand All @@ -680,7 +668,7 @@ def test_sort_custom_list(self):

task1 = task_store.new('1. My Task')
task2 = task_store.new('2. My Other Task')
task3 = task_store.new('3. My Other Other Task')
task_store.new('3. My Other Other Task')
task4 = task_store.new('4. My Other Other Other Task')

tasks = [task2, task4, task1]
Expand Down
2 changes: 0 additions & 2 deletions tests/core/test_taskview.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------

import os
import pytest
import re
from uuid import uuid4
from unittest import TestCase
Expand Down

0 comments on commit ee101cc

Please sign in to comment.