Skip to content

Commit d89ac05

Browse files
committed
Fix all mypy errors
1 parent 72b4832 commit d89ac05

File tree

7 files changed

+49
-44
lines changed

7 files changed

+49
-44
lines changed

.mypy.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[mypy]
2+
warn_unused_ignores = True

src/diffuse/dialogs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
import os
2121

22-
from diffuse import constants
22+
from diffuse import constants # type: ignore
2323
from diffuse import utils
2424

25-
import gi
25+
import gi # type: ignore
2626
gi.require_version('GObject', '2.0')
2727
gi.require_version('Gtk', '3.0')
28-
from gi.repository import GObject, Gtk # noqa: E402
28+
from gi.repository import GObject, Gtk # type: ignore # noqa: E402
2929

3030

3131
# the about dialog

src/diffuse/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@
2727

2828
from urllib.parse import urlparse
2929

30-
from diffuse import constants
30+
from diffuse import constants # type: ignore
3131
from diffuse import utils
3232
from diffuse.dialogs import AboutDialog, FileChooserDialog, NumericDialog, SearchDialog
3333
from diffuse.preferences import Preferences
3434
from diffuse.resources import theResources
3535
from diffuse.vcs.vcs_registry import VcsRegistry
36-
from diffuse.widgets import FileDiffViewer
36+
from diffuse.widgets import FileDiffViewerBase
3737
from diffuse.widgets import createMenu, LINE_MODE, CHAR_MODE, ALIGN_MODE
3838

39-
import gi
39+
import gi # type: ignore
4040
gi.require_version('GObject', '2.0')
4141
gi.require_version('Gtk', '3.0')
4242
gi.require_version('Gdk', '3.0')
4343
gi.require_version('GdkPixbuf', '2.0')
4444
gi.require_version('Pango', '1.0')
4545
gi.require_version('PangoCairo', '1.0')
46-
from gi.repository import GObject, Gtk, Gdk, GdkPixbuf, Pango, PangoCairo # noqa: E402
46+
from gi.repository import GObject, Gtk, Gdk, GdkPixbuf, Pango, PangoCairo # type: ignore # noqa: E402
4747

4848

4949
theVCSs = VcsRegistry()
@@ -110,8 +110,8 @@ def __init__(self, name=None, encoding=None, vcs=None, revision=None, label=None
110110
# this class displays tab for switching between viewers and dispatches menu
111111
# commands to the current viewer
112112
class Diffuse(Gtk.Window):
113-
# specialisation of FileDiffViewer for Diffuse
114-
class FileDiffViewer(FileDiffViewer):
113+
# specialization of FileDiffViewerBase for Diffuse
114+
class FileDiffViewer(FileDiffViewerBase):
115115
# pane header
116116
class PaneHeader(Gtk.Box):
117117
def __init__(self):
@@ -223,7 +223,7 @@ def setEncoding(self, s):
223223
self.encoding.set_text(s)
224224

225225
def __init__(self, n, prefs, title):
226-
FileDiffViewer.__init__(self, n, prefs)
226+
FileDiffViewerBase.__init__(self, n, prefs)
227227

228228
self.title = title
229229
self.status = ''

src/diffuse/preferences.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
import shlex
2424
import sys
2525

26-
from diffuse import constants
26+
from diffuse import constants # type: ignore
2727
from diffuse import utils
2828

29-
import gi
29+
import gi # type: ignore
3030
gi.require_version('Gtk', '3.0')
31-
from gi.repository import Gtk # noqa: E402
31+
from gi.repository import Gtk # type: ignore # noqa: E402
3232

3333

3434
# class to store preferences and construct a dialogue for manipulating them

src/diffuse/resources.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131

3232
from diffuse import utils
3333

34-
import gi
34+
import gi # type: ignore
3535
gi.require_version('Gdk', '3.0')
36-
from gi.repository import Gdk # noqa: E402
36+
from gi.repository import Gdk # type: ignore # noqa: E402
3737

3838

3939
class Resources:

src/diffuse/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
import subprocess
2424
import traceback
2525

26-
from diffuse import constants
26+
from diffuse import constants # type: ignore
2727

28-
import gi
28+
import gi # type: ignore
2929
gi.require_version('Gtk', '3.0')
30-
from gi.repository import Gtk # noqa: E402
30+
from gi.repository import Gtk # type: ignore # noqa: E402
3131

3232

3333
# convenience class for displaying a message dialogue

src/diffuse/widgets.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@
2121
import os
2222
import unicodedata
2323

24+
from typing import Dict
25+
2426
from diffuse import utils
2527
from diffuse.resources import theResources
2628

27-
import gi
29+
import gi # type: ignore
2830
gi.require_version('GObject', '2.0')
2931
gi.require_version('Gdk', '3.0')
3032
gi.require_version('Gtk', '3.0')
3133
gi.require_version('Pango', '1.0')
3234
gi.require_version('PangoCairo', '1.0')
33-
from gi.repository import GObject, Gdk, Gtk, Pango, PangoCairo # noqa: E402
35+
from gi.repository import GObject, Gdk, Gtk, Pango, PangoCairo # type: ignore # noqa: E402
3436

3537

3638
# mapping to column width of a character (tab will never be in this map)
37-
_char_width_cache = {}
39+
_char_width_cache: Dict[str, str] = {}
3840

3941
# the file diff viewer is always in one of these modes defining the cursor,
40-
# and hotkey behaviour
42+
# and hotkey behavior
4143
LINE_MODE = 0
4244
CHAR_MODE = 1
4345
ALIGN_MODE = 2
@@ -142,7 +144,7 @@ def redraw_region(self, x, y, w, h):
142144

143145

144146
# widget used to compare and merge text files
145-
class FileDiffViewer(Gtk.Grid):
147+
class FileDiffViewerBase(Gtk.Grid):
146148
# class describing a text pane
147149
class Pane:
148150
def __init__(self):
@@ -315,7 +317,7 @@ def __init__(self, n, prefs):
315317
self.hadj = Gtk.Adjustment.new(0, 0, 0, 0, 0, 0)
316318
self.vadj = Gtk.Adjustment.new(0, 0, 0, 0, 0, 0)
317319
for i in range(n):
318-
pane = FileDiffViewer.Pane()
320+
pane = FileDiffViewerBase.Pane()
319321
self.panes.append(pane)
320322

321323
# pane contents
@@ -712,7 +714,7 @@ def setFormat(self, f, fmt):
712714
pane = self.panes[f]
713715
if self.undoblock is not None:
714716
# create an Undo object for the action
715-
self.addUndo(FileDiffViewer.SetFormatUndo(f, fmt, pane.format))
717+
self.addUndo(FileDiffViewerBase.SetFormatUndo(f, fmt, pane.format))
716718
pane.format = fmt
717719
self.emit('format_changed', f, fmt)
718720

@@ -734,12 +736,12 @@ def redo(self, viewer):
734736
def instanceLine(self, f, i, reverse=False):
735737
if self.undoblock is not None:
736738
# create an Undo object for the action
737-
self.addUndo(FileDiffViewer.InstanceLineUndo(f, i, reverse))
739+
self.addUndo(FileDiffViewerBase.InstanceLineUndo(f, i, reverse))
738740
pane = self.panes[f]
739741
if reverse:
740742
pane.lines[i] = None
741743
else:
742-
line = FileDiffViewer.Line()
744+
line = FileDiffViewerBase.Line()
743745
pane.lines[i] = line
744746

745747
# Undo for changing the text for a Line object
@@ -774,7 +776,7 @@ def updateLineText(self, f, i, is_modified, text):
774776
flags = self.getMapFlags(f, i)
775777
if self.undoblock is not None:
776778
# create an Undo object for the action
777-
self.addUndo(FileDiffViewer.UpdateLineTextUndo(
779+
self.addUndo(FileDiffViewerBase.UpdateLineTextUndo(
778780
f,
779781
i,
780782
line.is_modified,
@@ -835,7 +837,7 @@ def redo(self, viewer):
835837
def insertNull(self, f, i, reverse):
836838
if self.undoblock is not None:
837839
# create an Undo object for the action
838-
self.addUndo(FileDiffViewer.InsertNullUndo(f, i, reverse))
840+
self.addUndo(FileDiffViewerBase.InsertNullUndo(f, i, reverse))
839841
pane = self.panes[f]
840842
lines = pane.lines
841843
# update/invalidate all relevant caches
@@ -866,7 +868,7 @@ def redo(self, viewer):
866868
def invalidateLineMatching(self, i, n, new_n):
867869
if self.undoblock is not None:
868870
# create an Undo object for the action
869-
self.addUndo(FileDiffViewer.InvalidateLineMatchingUndo(i, n, new_n))
871+
self.addUndo(FileDiffViewerBase.InvalidateLineMatchingUndo(i, n, new_n))
870872
# update/invalidate all relevant caches and queue widgets for redraw
871873
i2 = i + n
872874
for f, pane in enumerate(self.panes):
@@ -896,7 +898,7 @@ def redo(self, viewer):
896898
def alignmentChange(self, finished):
897899
if self.undoblock is not None:
898900
# create an Undo object for the action
899-
self.addUndo(FileDiffViewer.AlignmentChangeUndo(finished))
901+
self.addUndo(FileDiffViewerBase.AlignmentChangeUndo(finished))
900902
if finished:
901903
self.updateSize(False)
902904

@@ -939,7 +941,7 @@ def redo(self, viewer):
939941
def updateBlocks(self, blocks):
940942
if self.undoblock is not None:
941943
# create an Undo object for the action
942-
self.addUndo(FileDiffViewer.UpdateBlocksUndo(self.blocks, blocks))
944+
self.addUndo(FileDiffViewerBase.UpdateBlocksUndo(self.blocks, blocks))
943945
self.blocks = blocks
944946

945947
# insert 'n' blank lines in all panes
@@ -1031,7 +1033,8 @@ def redo(self, viewer):
10311033
def replaceLines(self, f, lines, new_lines, max_num, new_max_num):
10321034
if self.undoblock is not None:
10331035
# create an Undo object for the action
1034-
self.addUndo(FileDiffViewer.ReplaceLinesUndo(f, lines, new_lines, max_num, new_max_num))
1036+
self.addUndo(FileDiffViewerBase.ReplaceLinesUndo(
1037+
f, lines, new_lines, max_num, new_max_num))
10351038
pane = self.panes[f]
10361039
pane.lines = new_lines
10371040
# update/invalidate all relevant caches and queue widgets for redraw
@@ -1198,7 +1201,7 @@ def replaceContents(self, f, ss):
11981201
if n > 0:
11991202
blocks.append(n)
12001203
# create line objects for the text
1201-
Line = FileDiffViewer.Line
1204+
Line = FileDiffViewerBase.Line
12021205
mid = [[Line(j + 1, ss[j]) for j in range(n)]]
12031206

12041207
if f > 0:
@@ -1256,7 +1259,7 @@ def bakeEdits(self, f):
12561259
lines.append(None)
12571260
else:
12581261
line_num += 1
1259-
lines.append(FileDiffViewer.Line(line_num, s))
1262+
lines.append(FileDiffViewerBase.Line(line_num, s))
12601263

12611264
# update loaded pane
12621265
self.replaceLines(f, pane.lines, lines, pane.max_line_number, line_num)
@@ -1490,7 +1493,7 @@ def redo(self, viewer):
14901493
# selection
14911494
def recordEditMode(self):
14921495
if self.undoblock is not None:
1493-
self.addUndo(FileDiffViewer.EditModeUndo(
1496+
self.addUndo(FileDiffViewerBase.EditModeUndo(
14941497
self.mode,
14951498
self.current_pane,
14961499
self.current_line,
@@ -3243,7 +3246,7 @@ def redo(self, viewer):
32433246
# swap the contents of two panes
32443247
def swapPanes(self, f_dst, f_src):
32453248
if self.undoblock is not None:
3246-
self.addUndo(FileDiffViewer.SwapPanesUndo(f_dst, f_src))
3249+
self.addUndo(FileDiffViewerBase.SwapPanesUndo(f_dst, f_src))
32473250
self.current_pane = f_dst
32483251
f0 = self.panes[f_dst]
32493252
f1 = self.panes[f_src]
@@ -4128,10 +4131,10 @@ def _pixels(size):
41284131
return int(size / Pango.SCALE + 0.5)
41294132

41304133

4131-
# create 'title_changed' signal for FileDiffViewer
4132-
GObject.signal_new('swapped-panes', FileDiffViewer, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (int, int)) # noqa: E501
4133-
GObject.signal_new('num-edits-changed', FileDiffViewer, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (int, )) # noqa: E501
4134-
GObject.signal_new('mode-changed', FileDiffViewer, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, ()) # noqa: E501
4135-
GObject.signal_new('cursor-changed', FileDiffViewer, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, ()) # noqa: E501
4136-
GObject.signal_new('syntax-changed', FileDiffViewer, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (str, )) # noqa: E501
4137-
GObject.signal_new('format-changed', FileDiffViewer, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (int, int)) # noqa: E501
4134+
# create 'title_changed' signal for FileDiffViewerBase
4135+
GObject.signal_new('swapped-panes', FileDiffViewerBase, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (int, int)) # noqa: E501
4136+
GObject.signal_new('num-edits-changed', FileDiffViewerBase, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (int, )) # noqa: E501
4137+
GObject.signal_new('mode-changed', FileDiffViewerBase, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, ()) # noqa: E501
4138+
GObject.signal_new('cursor-changed', FileDiffViewerBase, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, ()) # noqa: E501
4139+
GObject.signal_new('syntax-changed', FileDiffViewerBase, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (str, )) # noqa: E501
4140+
GObject.signal_new('format-changed', FileDiffViewerBase, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (int, int)) # noqa: E501

0 commit comments

Comments
 (0)