[meld: 6/8] dirdiff: Fix lint errors and update CanonicalListing typing
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld: 6/8] dirdiff: Fix lint errors and update CanonicalListing typing
- Date: Sun, 30 Jan 2022 21:55:06 +0000 (UTC)
commit ef859d8edf8f9a0ba09688344bae5ab3d2f0a336
Author: Kai Willadsen <kai willadsen gmail com>
Date: Mon Jan 31 07:17:42 2022 +1000
dirdiff: Fix lint errors and update CanonicalListing typing
This adds in some additional typing for the update CanonicalListing
class, and also fixes some minor linting problems.
meld/dirdiff.py | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index d168423e..67de2187 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -27,7 +27,7 @@ import unicodedata
from collections import namedtuple
from decimal import Decimal
from mmap import ACCESS_COPY, mmap
-from typing import List, Optional, Tuple
+from typing import DefaultDict, List, Optional, Tuple
from gi.repository import Gdk, Gio, GLib, GObject, Gtk
@@ -263,6 +263,7 @@ class DirDiffTreeStore(tree.DiffTreeStore):
}
super().add_error(parent, msg, pane, defaults)
+
class ComparisonOptions:
def __init__(self):
self.ignore_case = False
@@ -272,26 +273,30 @@ class ComparisonOptions:
class CanonicalListing:
"""Multi-pane lists with canonicalised matching and error detection"""
- def __init__(self, n, compare):
+ items: DefaultDict[str, List[Optional[str]]]
+ errors: List[Tuple[int, str, str]]
+
+ def __init__(self, n: int, options: ComparisonOptions):
self.items = collections.defaultdict(lambda: [None] * n)
self.errors = []
- self.compare = compare
+ self.options = options
- def add(self, pane, item):
+ def add(self, pane: int, item: str):
# normalize the name depending on settings
ci = item
- if self.compare.ignore_case:
+ if self.options.ignore_case:
ci = ci.lower()
- if self.compare.normalize_encoding:
+ if self.options.normalize_encoding:
# NFC or NFD will work here, changing all composed or decomposed
# characters to the same set for matching only.
ci = unicodedata.normalize('NFC', ci)
# add the item to the comparison tree
- if self.items[ci][pane] is None:
+ existing_item = self.items[ci][pane]
+ if existing_item is None:
self.items[ci][pane] = item
else:
- self.errors.append((pane, item, self.items[ci][pane]))
+ self.errors.append((pane, item, existing_item))
def get(self):
def filled(seq):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]