Fix all mypy errors

This commit is contained in:
Romain Failliot 2021-11-22 20:50:05 -05:00
parent 72b4832ee4
commit d89ac0540b
7 changed files with 49 additions and 44 deletions

2
.mypy.ini Normal file
View File

@ -0,0 +1,2 @@
[mypy]
warn_unused_ignores = True

View File

@ -19,13 +19,13 @@
import os import os
from diffuse import constants from diffuse import constants # type: ignore
from diffuse import utils from diffuse import utils
import gi import gi # type: ignore
gi.require_version('GObject', '2.0') gi.require_version('GObject', '2.0')
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import GObject, Gtk # noqa: E402 from gi.repository import GObject, Gtk # type: ignore # noqa: E402
# the about dialog # the about dialog

View File

@ -27,23 +27,23 @@ import webbrowser
from urllib.parse import urlparse from urllib.parse import urlparse
from diffuse import constants from diffuse import constants # type: ignore
from diffuse import utils from diffuse import utils
from diffuse.dialogs import AboutDialog, FileChooserDialog, NumericDialog, SearchDialog from diffuse.dialogs import AboutDialog, FileChooserDialog, NumericDialog, SearchDialog
from diffuse.preferences import Preferences from diffuse.preferences import Preferences
from diffuse.resources import theResources from diffuse.resources import theResources
from diffuse.vcs.vcs_registry import VcsRegistry from diffuse.vcs.vcs_registry import VcsRegistry
from diffuse.widgets import FileDiffViewer from diffuse.widgets import FileDiffViewerBase
from diffuse.widgets import createMenu, LINE_MODE, CHAR_MODE, ALIGN_MODE from diffuse.widgets import createMenu, LINE_MODE, CHAR_MODE, ALIGN_MODE
import gi import gi # type: ignore
gi.require_version('GObject', '2.0') gi.require_version('GObject', '2.0')
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0') gi.require_version('Gdk', '3.0')
gi.require_version('GdkPixbuf', '2.0') gi.require_version('GdkPixbuf', '2.0')
gi.require_version('Pango', '1.0') gi.require_version('Pango', '1.0')
gi.require_version('PangoCairo', '1.0') gi.require_version('PangoCairo', '1.0')
from gi.repository import GObject, Gtk, Gdk, GdkPixbuf, Pango, PangoCairo # noqa: E402 from gi.repository import GObject, Gtk, Gdk, GdkPixbuf, Pango, PangoCairo # type: ignore # noqa: E402
theVCSs = VcsRegistry() theVCSs = VcsRegistry()
@ -110,8 +110,8 @@ class FileInfo:
# this class displays tab for switching between viewers and dispatches menu # this class displays tab for switching between viewers and dispatches menu
# commands to the current viewer # commands to the current viewer
class Diffuse(Gtk.Window): class Diffuse(Gtk.Window):
# specialisation of FileDiffViewer for Diffuse # specialization of FileDiffViewerBase for Diffuse
class FileDiffViewer(FileDiffViewer): class FileDiffViewer(FileDiffViewerBase):
# pane header # pane header
class PaneHeader(Gtk.Box): class PaneHeader(Gtk.Box):
def __init__(self): def __init__(self):
@ -223,7 +223,7 @@ class Diffuse(Gtk.Window):
self.encoding.set_text(s) self.encoding.set_text(s)
def __init__(self, n, prefs, title): def __init__(self, n, prefs, title):
FileDiffViewer.__init__(self, n, prefs) FileDiffViewerBase.__init__(self, n, prefs)
self.title = title self.title = title
self.status = '' self.status = ''

View File

@ -23,12 +23,12 @@ import os
import shlex import shlex
import sys import sys
from diffuse import constants from diffuse import constants # type: ignore
from diffuse import utils from diffuse import utils
import gi import gi # type: ignore
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk # noqa: E402 from gi.repository import Gtk # type: ignore # noqa: E402
# class to store preferences and construct a dialogue for manipulating them # class to store preferences and construct a dialogue for manipulating them

View File

@ -31,9 +31,9 @@ import shlex
from diffuse import utils from diffuse import utils
import gi import gi # type: ignore
gi.require_version('Gdk', '3.0') gi.require_version('Gdk', '3.0')
from gi.repository import Gdk # noqa: E402 from gi.repository import Gdk # type: ignore # noqa: E402
class Resources: class Resources:

View File

@ -23,11 +23,11 @@ import locale
import subprocess import subprocess
import traceback import traceback
from diffuse import constants from diffuse import constants # type: ignore
import gi import gi # type: ignore
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk # noqa: E402 from gi.repository import Gtk # type: ignore # noqa: E402
# convenience class for displaying a message dialogue # convenience class for displaying a message dialogue

View File

@ -21,23 +21,25 @@ import difflib
import os import os
import unicodedata import unicodedata
from typing import Dict
from diffuse import utils from diffuse import utils
from diffuse.resources import theResources from diffuse.resources import theResources
import gi import gi # type: ignore
gi.require_version('GObject', '2.0') gi.require_version('GObject', '2.0')
gi.require_version('Gdk', '3.0') gi.require_version('Gdk', '3.0')
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('Pango', '1.0') gi.require_version('Pango', '1.0')
gi.require_version('PangoCairo', '1.0') gi.require_version('PangoCairo', '1.0')
from gi.repository import GObject, Gdk, Gtk, Pango, PangoCairo # noqa: E402 from gi.repository import GObject, Gdk, Gtk, Pango, PangoCairo # type: ignore # noqa: E402
# mapping to column width of a character (tab will never be in this map) # mapping to column width of a character (tab will never be in this map)
_char_width_cache = {} _char_width_cache: Dict[str, str] = {}
# the file diff viewer is always in one of these modes defining the cursor, # the file diff viewer is always in one of these modes defining the cursor,
# and hotkey behaviour # and hotkey behavior
LINE_MODE = 0 LINE_MODE = 0
CHAR_MODE = 1 CHAR_MODE = 1
ALIGN_MODE = 2 ALIGN_MODE = 2
@ -142,7 +144,7 @@ class ScrolledWindow(Gtk.Grid):
# widget used to compare and merge text files # widget used to compare and merge text files
class FileDiffViewer(Gtk.Grid): class FileDiffViewerBase(Gtk.Grid):
# class describing a text pane # class describing a text pane
class Pane: class Pane:
def __init__(self): def __init__(self):
@ -315,7 +317,7 @@ class FileDiffViewer(Gtk.Grid):
self.hadj = Gtk.Adjustment.new(0, 0, 0, 0, 0, 0) self.hadj = Gtk.Adjustment.new(0, 0, 0, 0, 0, 0)
self.vadj = Gtk.Adjustment.new(0, 0, 0, 0, 0, 0) self.vadj = Gtk.Adjustment.new(0, 0, 0, 0, 0, 0)
for i in range(n): for i in range(n):
pane = FileDiffViewer.Pane() pane = FileDiffViewerBase.Pane()
self.panes.append(pane) self.panes.append(pane)
# pane contents # pane contents
@ -712,7 +714,7 @@ class FileDiffViewer(Gtk.Grid):
pane = self.panes[f] pane = self.panes[f]
if self.undoblock is not None: if self.undoblock is not None:
# create an Undo object for the action # create an Undo object for the action
self.addUndo(FileDiffViewer.SetFormatUndo(f, fmt, pane.format)) self.addUndo(FileDiffViewerBase.SetFormatUndo(f, fmt, pane.format))
pane.format = fmt pane.format = fmt
self.emit('format_changed', f, fmt) self.emit('format_changed', f, fmt)
@ -734,12 +736,12 @@ class FileDiffViewer(Gtk.Grid):
def instanceLine(self, f, i, reverse=False): def instanceLine(self, f, i, reverse=False):
if self.undoblock is not None: if self.undoblock is not None:
# create an Undo object for the action # create an Undo object for the action
self.addUndo(FileDiffViewer.InstanceLineUndo(f, i, reverse)) self.addUndo(FileDiffViewerBase.InstanceLineUndo(f, i, reverse))
pane = self.panes[f] pane = self.panes[f]
if reverse: if reverse:
pane.lines[i] = None pane.lines[i] = None
else: else:
line = FileDiffViewer.Line() line = FileDiffViewerBase.Line()
pane.lines[i] = line pane.lines[i] = line
# Undo for changing the text for a Line object # Undo for changing the text for a Line object
@ -774,7 +776,7 @@ class FileDiffViewer(Gtk.Grid):
flags = self.getMapFlags(f, i) flags = self.getMapFlags(f, i)
if self.undoblock is not None: if self.undoblock is not None:
# create an Undo object for the action # create an Undo object for the action
self.addUndo(FileDiffViewer.UpdateLineTextUndo( self.addUndo(FileDiffViewerBase.UpdateLineTextUndo(
f, f,
i, i,
line.is_modified, line.is_modified,
@ -835,7 +837,7 @@ class FileDiffViewer(Gtk.Grid):
def insertNull(self, f, i, reverse): def insertNull(self, f, i, reverse):
if self.undoblock is not None: if self.undoblock is not None:
# create an Undo object for the action # create an Undo object for the action
self.addUndo(FileDiffViewer.InsertNullUndo(f, i, reverse)) self.addUndo(FileDiffViewerBase.InsertNullUndo(f, i, reverse))
pane = self.panes[f] pane = self.panes[f]
lines = pane.lines lines = pane.lines
# update/invalidate all relevant caches # update/invalidate all relevant caches
@ -866,7 +868,7 @@ class FileDiffViewer(Gtk.Grid):
def invalidateLineMatching(self, i, n, new_n): def invalidateLineMatching(self, i, n, new_n):
if self.undoblock is not None: if self.undoblock is not None:
# create an Undo object for the action # create an Undo object for the action
self.addUndo(FileDiffViewer.InvalidateLineMatchingUndo(i, n, new_n)) self.addUndo(FileDiffViewerBase.InvalidateLineMatchingUndo(i, n, new_n))
# update/invalidate all relevant caches and queue widgets for redraw # update/invalidate all relevant caches and queue widgets for redraw
i2 = i + n i2 = i + n
for f, pane in enumerate(self.panes): for f, pane in enumerate(self.panes):
@ -896,7 +898,7 @@ class FileDiffViewer(Gtk.Grid):
def alignmentChange(self, finished): def alignmentChange(self, finished):
if self.undoblock is not None: if self.undoblock is not None:
# create an Undo object for the action # create an Undo object for the action
self.addUndo(FileDiffViewer.AlignmentChangeUndo(finished)) self.addUndo(FileDiffViewerBase.AlignmentChangeUndo(finished))
if finished: if finished:
self.updateSize(False) self.updateSize(False)
@ -939,7 +941,7 @@ class FileDiffViewer(Gtk.Grid):
def updateBlocks(self, blocks): def updateBlocks(self, blocks):
if self.undoblock is not None: if self.undoblock is not None:
# create an Undo object for the action # create an Undo object for the action
self.addUndo(FileDiffViewer.UpdateBlocksUndo(self.blocks, blocks)) self.addUndo(FileDiffViewerBase.UpdateBlocksUndo(self.blocks, blocks))
self.blocks = blocks self.blocks = blocks
# insert 'n' blank lines in all panes # insert 'n' blank lines in all panes
@ -1031,7 +1033,8 @@ class FileDiffViewer(Gtk.Grid):
def replaceLines(self, f, lines, new_lines, max_num, new_max_num): def replaceLines(self, f, lines, new_lines, max_num, new_max_num):
if self.undoblock is not None: if self.undoblock is not None:
# create an Undo object for the action # create an Undo object for the action
self.addUndo(FileDiffViewer.ReplaceLinesUndo(f, lines, new_lines, max_num, new_max_num)) self.addUndo(FileDiffViewerBase.ReplaceLinesUndo(
f, lines, new_lines, max_num, new_max_num))
pane = self.panes[f] pane = self.panes[f]
pane.lines = new_lines pane.lines = new_lines
# update/invalidate all relevant caches and queue widgets for redraw # update/invalidate all relevant caches and queue widgets for redraw
@ -1198,7 +1201,7 @@ class FileDiffViewer(Gtk.Grid):
if n > 0: if n > 0:
blocks.append(n) blocks.append(n)
# create line objects for the text # create line objects for the text
Line = FileDiffViewer.Line Line = FileDiffViewerBase.Line
mid = [[Line(j + 1, ss[j]) for j in range(n)]] mid = [[Line(j + 1, ss[j]) for j in range(n)]]
if f > 0: if f > 0:
@ -1256,7 +1259,7 @@ class FileDiffViewer(Gtk.Grid):
lines.append(None) lines.append(None)
else: else:
line_num += 1 line_num += 1
lines.append(FileDiffViewer.Line(line_num, s)) lines.append(FileDiffViewerBase.Line(line_num, s))
# update loaded pane # update loaded pane
self.replaceLines(f, pane.lines, lines, pane.max_line_number, line_num) self.replaceLines(f, pane.lines, lines, pane.max_line_number, line_num)
@ -1490,7 +1493,7 @@ class FileDiffViewer(Gtk.Grid):
# selection # selection
def recordEditMode(self): def recordEditMode(self):
if self.undoblock is not None: if self.undoblock is not None:
self.addUndo(FileDiffViewer.EditModeUndo( self.addUndo(FileDiffViewerBase.EditModeUndo(
self.mode, self.mode,
self.current_pane, self.current_pane,
self.current_line, self.current_line,
@ -3243,7 +3246,7 @@ class FileDiffViewer(Gtk.Grid):
# swap the contents of two panes # swap the contents of two panes
def swapPanes(self, f_dst, f_src): def swapPanes(self, f_dst, f_src):
if self.undoblock is not None: if self.undoblock is not None:
self.addUndo(FileDiffViewer.SwapPanesUndo(f_dst, f_src)) self.addUndo(FileDiffViewerBase.SwapPanesUndo(f_dst, f_src))
self.current_pane = f_dst self.current_pane = f_dst
f0 = self.panes[f_dst] f0 = self.panes[f_dst]
f1 = self.panes[f_src] f1 = self.panes[f_src]
@ -4128,10 +4131,10 @@ def _pixels(size):
return int(size / Pango.SCALE + 0.5) return int(size / Pango.SCALE + 0.5)
# create 'title_changed' signal for FileDiffViewer # create 'title_changed' signal for FileDiffViewerBase
GObject.signal_new('swapped-panes', FileDiffViewer, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (int, int)) # noqa: E501 GObject.signal_new('swapped-panes', FileDiffViewerBase, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (int, int)) # noqa: E501
GObject.signal_new('num-edits-changed', FileDiffViewer, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (int, )) # noqa: E501 GObject.signal_new('num-edits-changed', FileDiffViewerBase, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (int, )) # noqa: E501
GObject.signal_new('mode-changed', FileDiffViewer, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, ()) # noqa: E501 GObject.signal_new('mode-changed', FileDiffViewerBase, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, ()) # noqa: E501
GObject.signal_new('cursor-changed', FileDiffViewer, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, ()) # noqa: E501 GObject.signal_new('cursor-changed', FileDiffViewerBase, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, ()) # noqa: E501
GObject.signal_new('syntax-changed', FileDiffViewer, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (str, )) # noqa: E501 GObject.signal_new('syntax-changed', FileDiffViewerBase, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (str, )) # noqa: E501
GObject.signal_new('format-changed', FileDiffViewer, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (int, int)) # noqa: E501 GObject.signal_new('format-changed', FileDiffViewerBase, GObject.SignalFlags.RUN_LAST, GObject.TYPE_NONE, (int, int)) # noqa: E501