[pygobject] PEP8: Consistent comparisons against True, False, and None



commit ef06548b0dc6aee0e8ab208a78966dc1d5d917ee
Author: Martin Pitt <martinpitt gnome org>
Date:   Fri Jun 22 12:24:32 2012 +0200

    PEP8: Consistent comparisons against True, False, and None
    
    Spotted by current pep8 checker.

 demos/gtk-demo/demos/clipboard.py   |    4 ++--
 demos/gtk-demo/demos/drawingarea.py |    4 ++--
 demos/gtk-demo/gtk-demo.py          |    8 ++++----
 gi/overrides/Gdk.py                 |    2 +-
 gi/overrides/Gtk.py                 |    2 +-
 tests/test_gi.py                    |    4 ++--
 tests/test_overrides.py             |    3 +--
 7 files changed, 13 insertions(+), 14 deletions(-)
---
diff --git a/demos/gtk-demo/demos/clipboard.py b/demos/gtk-demo/demos/clipboard.py
index 4fb7b2e..330aa21 100644
--- a/demos/gtk-demo/demos/clipboard.py
+++ b/demos/gtk-demo/demos/clipboard.py
@@ -150,7 +150,7 @@ class ClipboardApp:
         clipboard.set_text(entry.get_text(), -1)
 
     def paste_received(self, clipboard, text, entry):
-        if text != None:
+        if text is not None:
             entry.set_text(text)
 
     def paste_button_clicked(self, button, entry):
@@ -199,7 +199,7 @@ class ClipboardApp:
         clipboard = Gtk.Clipboard.get(atom)
         pixbuf = clipboard.wait_for_image()
 
-        if pixbuf != None:
+        if pixbuf is not None:
             data.set_from_pixbuf(pixbuf)
 
     def button_press(self, widget, event, data):
diff --git a/demos/gtk-demo/demos/drawingarea.py b/demos/gtk-demo/demos/drawingarea.py
index 03751a6..aea18b5 100644
--- a/demos/gtk-demo/demos/drawingarea.py
+++ b/demos/gtk-demo/demos/drawingarea.py
@@ -168,7 +168,7 @@ class DrawingAreaApp:
         return True
 
     def scribble_motion_notify_event(self, da, event):
-        if self.surface == None:  # paranoia check, in case we haven't gotten a configure event
+        if self.surface is None:  # paranoia check, in case we haven't gotten a configure event
             return False
 
         # This call is very important; it requests the next motion event.
@@ -189,7 +189,7 @@ class DrawingAreaApp:
         return True
 
     def scribble_button_press_event(self, da, event):
-        if self.surface == None:  # paranoia check, in case we haven't gotten a configure event
+        if self.surface is None:  # paranoia check, in case we haven't gotten a configure event
             return False
 
         if event.button == 1:
diff --git a/demos/gtk-demo/gtk-demo.py b/demos/gtk-demo/gtk-demo.py
index 031b964..8774685 100755
--- a/demos/gtk-demo/gtk-demo.py
+++ b/demos/gtk-demo/gtk-demo.py
@@ -366,10 +366,10 @@ class GtkDemoWindow(Gtk.Window):
                     prepare_iters()
                     self.source_buffer.apply_tag_by_name('italic', start_iter, end_iter)
                 else:
-                    if is_func is True:
+                    if is_func:
                         prepare_iters()
                         self.source_buffer.apply_tag_by_name('bold', start_iter, end_iter)
-                    elif is_decorator is True:
+                    elif is_decorator:
                         prepare_iters()
                         self.source_buffer.apply_tag_by_name('decorator', start_iter, end_iter)
             elif tok_type == tokenize.STRING:
@@ -387,10 +387,10 @@ class GtkDemoWindow(Gtk.Window):
                     is_decorator = True
                     continue
 
-            if is_func is True:
+            if is_func:
                 is_func = False
 
-            if is_decorator is True:
+            if is_decorator:
                 is_decorator = False
 
 
diff --git a/gi/overrides/Gdk.py b/gi/overrides/Gdk.py
index 66d47ef..20ef910 100644
--- a/gi/overrides/Gdk.py
+++ b/gi/overrides/Gdk.py
@@ -255,7 +255,7 @@ def _gsuccess_mask(func):
     def cull_success(*args):
         result = func(*args)
         success = result[0]
-        if success == False:
+        if not success:
             return None
         else:
             if len(result) == 2:
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 1043cbf..fbb5076 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -477,7 +477,7 @@ class MessageDialog(Gtk.MessageDialog, Dialog):
                  message_format=None,
                  **kwds):
 
-        if message_format != None:
+        if message_format:
             kwds['text'] = message_format
 
         # type keyword is used for backwards compat with PyGTK
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 50b5a25..e314e50 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1767,10 +1767,10 @@ class TestPythonGObject(unittest.TestCase):
 
         _object = SubObject()
         _object.call_vfunc_with_callback()
-        self.assertTrue(_object.worked == True)
+        self.assertTrue(_object.worked)
         _object.worked = False
         _object.call_vfunc_with_callback()
-        self.assertTrue(_object.worked == True)
+        self.assertTrue(_object.worked)
 
 
 class TestMultiOutputArgs(unittest.TestCase):
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index 67e51fe..7dc30de 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -1344,8 +1344,7 @@ class TestGtk(unittest.TestCase):
         p2 = Gtk.TreePath.new_from_string('1:2:3')
         self.assertEqual(p1, p2)
         self.assertEqual(str(p1), '1:2:3')
-        self.assertTrue(p1 != None)
-        self.assertFalse(p1 == None)
+        self.assertNotEqual(p1, None)
         self.assertTrue(p1 > None)
         self.assertTrue(p1 >= None)
         self.assertFalse(p1 < None)



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