diff --git a/GTG/core/base_store.py b/GTG/core/base_store.py index 30971b8a22..e4c070de11 100644 --- a/GTG/core/base_store.py +++ b/GTG/core/base_store.py @@ -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__) diff --git a/GTG/core/clipboard.py b/GTG/core/clipboard.py index 2eefb09f9d..a2d76a5702 100644 --- a/GTG/core/clipboard.py +++ b/GTG/core/clipboard.py @@ -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(): diff --git a/GTG/core/config.py b/GTG/core/config.py index af7fe55174..197e56c448 100644 --- a/GTG/core/config.py +++ b/GTG/core/config.py @@ -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 diff --git a/GTG/core/tags.py b/GTG/core/tags.py index 2eeb69d9e4..2d5915ac48 100644 --- a/GTG/core/tags.py +++ b/GTG/core/tags.py @@ -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 @@ -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: @@ -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') @@ -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') diff --git a/GTG/core/tasks.py b/GTG/core/tasks.py index 66eecf253c..0ab9cee8cb 100644 --- a/GTG/core/tasks.py +++ b/GTG/core/tasks.py @@ -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: @@ -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: diff --git a/GTG/gtk/backends/parameters_ui/__init__.py b/GTG/gtk/backends/parameters_ui/__init__.py index 58339113a8..025e331731 100644 --- a/GTG/gtk/backends/parameters_ui/__init__.py +++ b/GTG/gtk/backends/parameters_ui/__init__.py @@ -23,8 +23,6 @@ server and client """ -import functools - from gi.repository import Gtk from GTG.backends.generic_backend import GenericBackend diff --git a/GTG/gtk/browser/adaptive_button.py b/GTG/gtk/browser/adaptive_button.py index 7340dc2ee4..0252db6883 100644 --- a/GTG/gtk/browser/adaptive_button.py +++ b/GTG/gtk/browser/adaptive_button.py @@ -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 diff --git a/GTG/gtk/browser/main_window.py b/GTG/gtk/browser/main_window.py index 0b983a6395..5439d24aa1 100644 --- a/GTG/gtk/browser/main_window.py +++ b/GTG/gtk/browser/main_window.py @@ -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() diff --git a/GTG/gtk/browser/task_pane.py b/GTG/gtk/browser/task_pane.py index 82fc36e8c1..d46b300226 100644 --- a/GTG/gtk/browser/task_pane.py +++ b/GTG/gtk/browser/task_pane.py @@ -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 _ diff --git a/GTG/gtk/colors.py b/GTG/gtk/colors.py index 71a84bc15c..38a914e107 100644 --- a/GTG/gtk/colors.py +++ b/GTG/gtk/colors.py @@ -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): diff --git a/GTG/gtk/editor/calendar.py b/GTG/gtk/editor/calendar.py index 8cb8781a7d..5eccf65abe 100644 --- a/GTG/gtk/editor/calendar.py +++ b/GTG/gtk/editor/calendar.py @@ -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() diff --git a/GTG/gtk/editor/recurring_menu.py b/GTG/gtk/editor/recurring_menu.py index ada27e7df9..3a88688c2b 100644 --- a/GTG/gtk/editor/recurring_menu.py +++ b/GTG/gtk/editor/recurring_menu.py @@ -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]) diff --git a/GTG/gtk/errorhandler.py b/GTG/gtk/errorhandler.py index caf4d266c9..673340e28e 100644 --- a/GTG/gtk/errorhandler.py +++ b/GTG/gtk/errorhandler.py @@ -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() diff --git a/GTG/plugins/gamify/gamify.py b/GTG/plugins/gamify/gamify.py index 5a062f14e3..7f0d23bca3 100644 --- a/GTG/plugins/gamify/gamify.py +++ b/GTG/plugins/gamify/gamify.py @@ -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') diff --git a/GTG/plugins/unmaintained/tomboy/tomboy.py b/GTG/plugins/unmaintained/tomboy/tomboy.py index e7ea3e1170..a19b870562 100644 --- a/GTG/plugins/unmaintained/tomboy/tomboy.py +++ b/GTG/plugins/unmaintained/tomboy/tomboy.py @@ -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) diff --git a/scripts/anonymize_task_file.py b/scripts/anonymize_task_file.py index cbf08c0ac2..d879b126ff 100755 --- a/scripts/anonymize_task_file.py +++ b/scripts/anonymize_task_file.py @@ -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) diff --git a/tests/core/test_quickadd.py b/tests/core/test_quickadd.py index 15433c268d..040bb5de01 100644 --- a/tests/core/test_quickadd.py +++ b/tests/core/test_quickadd.py @@ -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)) @@ -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)) diff --git a/tests/core/test_saved_search.py b/tests/core/test_saved_search.py index 9a10679eca..b1fbdfc991 100644 --- a/tests/core/test_saved_search.py +++ b/tests/core/test_saved_search.py @@ -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() diff --git a/tests/core/test_tag_store.py b/tests/core/test_tag_store.py index ff8d151fdd..a5ed02470f 100644 --- a/tests/core/test_tag_store.py +++ b/tests/core/test_tag_store.py @@ -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) @@ -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) diff --git a/tests/core/test_task.py b/tests/core/test_task.py index 5db3419315..784008a386 100644 --- a/tests/core/test_task.py +++ b/tests/core/test_task.py @@ -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) @@ -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') @@ -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) @@ -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() @@ -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] diff --git a/tests/core/test_taskview.py b/tests/core/test_taskview.py index bf7b4b947f..7478161149 100644 --- a/tests/core/test_taskview.py +++ b/tests/core/test_taskview.py @@ -16,8 +16,6 @@ # this program. If not, see . # ----------------------------------------------------------------------------- -import os -import pytest import re from uuid import uuid4 from unittest import TestCase