[pitivi] Fix pylint unidiomatic-typecheck



commit 44f1efca48297be5121bc436f713112b26e38a27
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Oct 29 21:11:16 2019 +0100

    Fix pylint unidiomatic-typecheck

 pitivi/render.py               |  2 +-
 pitivi/settings.py             |  4 ++--
 pitivi/timeline/timeline.py    |  2 +-
 pitivi/utils/loggable.py       |  2 +-
 pitivi/utils/ui.py             | 14 +++++++-------
 pitivi/utils/widgets.py        | 10 +++++-----
 pitivi/viewer/overlay_stack.py |  2 +-
 pre-commit.hook                |  2 --
 8 files changed, 18 insertions(+), 20 deletions(-)
---
diff --git a/pitivi/render.py b/pitivi/render.py
index 2f9ba62a..c080d6a4 100644
--- a/pitivi/render.py
+++ b/pitivi/render.py
@@ -219,7 +219,7 @@ class Encoders(Loggable):
 
     def is_supported(self, factory):
         """Returns whether the specified factory is supported."""
-        if type(factory) is str:
+        if isinstance(factory, str):
             factory = self.factories_by_name[factory]
         return factory in self.supported_muxers or\
             factory in self.supported_aencoders or\
diff --git a/pitivi/settings.py b/pitivi/settings.py
index a4c0a680..f972d2b9 100644
--- a/pitivi/settings.py
+++ b/pitivi/settings.py
@@ -177,10 +177,10 @@ class GlobalSettings(GObject.Object, Loggable):
         return value
 
     def _write_value(self, section, key, value):
-        if type(value) == list:
+        if isinstance(value, list):
             value = "\n" + "\n".join(value)
             self._config.set(section, key, value)
-        elif type(value) == Gdk.RGBA:
+        elif isinstance(value, Gdk.RGBA):
             self.set_rgba(section, key, value)
         else:
             self._config.set(section, key, str(value))
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 975c5e9b..f0adc2dc 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -839,7 +839,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
 
     def _motion_notify_event_cb(self, unused_widget, event):
         if self.draggingElement:
-            if type(self.draggingElement) == TransitionClip and \
+            if isinstance(self.draggingElement, TransitionClip) and \
                     not self.__clickedHandle:
                 # Don't allow dragging a transition.
                 return False
diff --git a/pitivi/utils/loggable.py b/pitivi/utils/loggable.py
index d50706d5..70f0f404 100644
--- a/pitivi/utils/loggable.py
+++ b/pitivi/utils/loggable.py
@@ -603,7 +603,7 @@ def _preformatLevels(enableColorOutput):
     terminal_controller = TerminalController()
     for level in ERROR, WARN, FIXME, INFO, DEBUG, LOG:
         if enableColorOutput:
-            if type(terminal_controller.BOLD) == bytes:
+            if isinstance(terminal_controller.BOLD, bytes):
                 formatter = ''.join(
                     (terminal_controller.BOLD.decode(),
                      getattr(terminal_controller, COLORS[level]).decode(),
diff --git a/pitivi/utils/ui.py b/pitivi/utils/ui.py
index 3138219c..ac2be35a 100644
--- a/pitivi/utils/ui.py
+++ b/pitivi/utils/ui.py
@@ -415,9 +415,9 @@ def hex_to_rgb(value):
 
 
 def set_cairo_color(context, color):
-    if type(color) is Gdk.RGBA:
+    if isinstance(color, Gdk.RGBA):
         cairo_color = (float(color.red), float(color.green), float(color.blue))
-    elif type(color) is tuple:
+    elif isinstance(color, tuple):
         # Cairo's set_source_rgb function expects values from 0.0 to 1.0
         cairo_color = [max(0, min(1, x / 255.0)) for x in color]
     else:
@@ -518,7 +518,7 @@ def beautify_project_path(path):
 
 
 def beautify_stream(stream):
-    if type(stream) is DiscovererAudioInfo:
+    if isinstance(stream, DiscovererAudioInfo):
         if stream.get_depth() == 0:
             return None
 
@@ -529,7 +529,7 @@ def beautify_stream(stream):
         return templ % (stream.get_channels(), stream.get_sample_rate(),
                         stream.get_depth())
 
-    elif type(stream) is DiscovererVideoInfo:
+    elif isinstance(stream, DiscovererVideoInfo):
         par = stream.get_par_num() / stream.get_par_denom()
         width = stream.get_natural_width()
         height = stream.get_natural_height()
@@ -541,17 +541,17 @@ def beautify_stream(stream):
             templ = _("<b>Image:</b> %d×%d <i>pixels</i>")
             return templ % (par * width, height)
 
-    elif type(stream) is DiscovererSubtitleInfo:
+    elif isinstance(stream, DiscovererSubtitleInfo):
         # Ignore subtitle streams
         return None
 
-    elif type(stream) is DiscovererStreamInfo:
+    elif isinstance(stream, DiscovererStreamInfo):
         caps = stream.get_caps().to_string()
         if caps in ("application/x-subtitle", "application/x-id3", "text"):
             # Ignore all audio ID3 tags and subtitle tracks, we don't show them
             return None
 
-    raise NotImplementedError
+    raise ValueError("Unsupported stream type: %s" % stream)
 
 
 def time_to_string(value):
diff --git a/pitivi/utils/widgets.py b/pitivi/utils/widgets.py
index 12bff2df..b174a5c9 100644
--- a/pitivi/utils/widgets.py
+++ b/pitivi/utils/widgets.py
@@ -146,7 +146,7 @@ class TextWidget(Gtk.Box, DynamicWidget):
         self.text.connect("changed", self.__text_changed_cb)
         self.text.connect("activate", self.__activate_cb)
         if matches:
-            if type(matches) is str:
+            if isinstance(matches, str):
                 self.matches = re.compile(matches)
             else:
                 self.matches = matches
@@ -381,7 +381,7 @@ class FractionWidget(TextWidget, DynamicWidget):
         choices = []
         if presets:
             for preset in presets:
-                if type(preset) is str:
+                if isinstance(preset, str):
                     strval = preset
                     preset = self._parseText(preset)
                 else:
@@ -403,7 +403,7 @@ class FractionWidget(TextWidget, DynamicWidget):
     def addPresets(self, presets):
         choices = []
         for preset in presets:
-            if type(preset) is str:
+            if isinstance(preset, str):
                 strval = preset
                 preset = self._parseText(preset)
             else:
@@ -415,7 +415,7 @@ class FractionWidget(TextWidget, DynamicWidget):
         self.addChoices(choices)
 
     def setWidgetValue(self, value):
-        if type(value) is str:
+        if isinstance(value, str):
             value = self._parseText(value)
         elif not hasattr(value, "denom"):
             value = Gst.Fraction(value)
@@ -937,7 +937,7 @@ class GstElementSettingsWidget(Gtk.Box, Loggable):
         self.show_all()
 
     def _make_widget_from_gvalue(self, gvalue, default):
-        if type(gvalue) == Gst.ValueList:
+        if isinstance(gvalue, Gst.ValueList):
             choices = []
             for val in gvalue:
                 choices.append([val, val])
diff --git a/pitivi/viewer/overlay_stack.py b/pitivi/viewer/overlay_stack.py
index 3af228e6..cc8dc7f2 100644
--- a/pitivi/viewer/overlay_stack.py
+++ b/pitivi/viewer/overlay_stack.py
@@ -75,7 +75,7 @@ class OverlayStack(Gtk.Overlay, Loggable):
         if source in self.__overlays:
             return self.__overlays[source]
 
-        if type(source) == GES.TitleSource:
+        if isinstance(source, GES.TitleSource):
             overlay = TitleOverlay(self, source)
         else:
             overlay = MoveScaleOverlay(self, self.app.action_log, source)
diff --git a/pre-commit.hook b/pre-commit.hook
index 5751009f..9cc7e0db 100755
--- a/pre-commit.hook
+++ b/pre-commit.hook
@@ -19,7 +19,6 @@ pitivi/medialibrary.py
 pitivi/preset.py
 pitivi/project.py
 pitivi/render.py
-pitivi/settings.py
 pitivi/timeline/elements.py
 pitivi/timeline/timeline.py
 pitivi/titleeditor.py
@@ -32,7 +31,6 @@ pitivi/utils/ui.py
 pitivi/utils/validate.py
 pitivi/utils/widgets.py
 pitivi/viewer/move_scale_overlay.py
-pitivi/viewer/overlay_stack.py
 pitivi/viewer/viewer.py
 tests/common.py
 tests/test_medialibrary.py


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]