From a5119351519926971240f61d0c23a5fc5d00743e Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 9 Oct 2012 11:14:59 -0400 Subject: compare with equality not identity (issue #16172) Patch from Serhiy Storchaka. --- Lib/test/test_winsound.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_winsound.py b/Lib/test/test_winsound.py index 34c3dea..eb7f75f 100644 --- a/Lib/test/test_winsound.py +++ b/Lib/test/test_winsound.py @@ -16,16 +16,12 @@ def has_sound(sound): try: # Ask the mixer API for the number of devices it knows about. # When there are no devices, PlaySound will fail. - if ctypes.windll.winmm.mixerGetNumDevs() is 0: + if ctypes.windll.winmm.mixerGetNumDevs() == 0: return False key = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, "AppEvents\Schemes\Apps\.Default\{0}\.Default".format(sound)) - value = winreg.EnumValue(key, 0)[1] - if value is not "": - return True - else: - return False + return winreg.EnumValue(key, 0)[1] != "" except WindowsError: return False -- cgit v0.12 From b29614e047110f4d9af993a6cdec4e3fb7ef9738 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 9 Oct 2012 11:16:03 -0400 Subject: compare singletons by identity not equality (closes #16712) Patch from Serhiy Storchaka. --- Lib/os.py | 2 +- Lib/pydoc.py | 4 ++-- Lib/test/support.py | 2 +- Lib/test/test_ftplib.py | 2 +- Lib/test/test_posix.py | 4 ++-- Lib/test/test_sys.py | 2 +- Lib/unittest/case.py | 2 +- Tools/gdb/libpython.py | 2 +- Tools/scripts/texi2html.py | 10 +++++----- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Lib/os.py b/Lib/os.py index 842512a..84eeaeb 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -985,7 +985,7 @@ def popen(cmd, mode="r", buffering=-1): raise TypeError("invalid cmd type (%s, expected string)" % type(cmd)) if mode not in ("r", "w"): raise ValueError("invalid mode %r" % mode) - if buffering == 0 or buffering == None: + if buffering == 0 or buffering is None: raise ValueError("popen() does not support unbuffered streams") import subprocess, io if mode == "r": diff --git a/Lib/pydoc.py b/Lib/pydoc.py index aa296c4..fa531e9 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -2551,8 +2551,8 @@ def cli(): if opt == '-w': writing = True - if start_server == True: - if port == None: + if start_server: + if port is None: port = 0 browse(port, open_browser=open_browser) return diff --git a/Lib/test/support.py b/Lib/test/support.py index 014bcf5..c5640e0 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -1232,7 +1232,7 @@ def run_with_tz(tz): try: return func(*args, **kwds) finally: - if orig_tz == None: + if orig_tz is None: del os.environ['TZ'] else: os.environ['TZ'] = orig_tz diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index 7028f46..299a146 100644 --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -342,7 +342,7 @@ if ssl is not None: # http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html pass self._ssl_closing = False - if getattr(self, '_ccc', False) == False: + if getattr(self, '_ccc', False) is False: super(SSLConnection, self).close() else: pass diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 4e7a37c..f59607b 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -651,7 +651,7 @@ class PosixTester(unittest.TestCase): groups = idg.read().strip() ret = idg.close() - if ret != None or not groups: + if ret is not None or not groups: raise unittest.SkipTest("need working 'id -G'") self.assertEqual( @@ -665,7 +665,7 @@ class PosixTester(unittest.TestCase): groups = idg.read().strip() ret = idg.close() - if ret != None or not groups: + if ret is not None or not groups: raise unittest.SkipTest("need working 'id -G'") # 'id -G' and 'os.getgroups()' should return the same diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 6e0c6ee..e5ec85c 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -897,7 +897,7 @@ class SizeofTest(unittest.TestCase): except TypeError: tb = sys.exc_info()[2] # traceback - if tb != None: + if tb is not None: check(tb, size('2P2i')) # symtable entry # XXX diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 28f0a2d..f334865 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -736,7 +736,7 @@ class TestCase(object): msg: Optional message to use on failure instead of a list of differences. """ - if seq_type != None: + if seq_type is not None: seq_type_name = seq_type.__name__ if not isinstance(seq1, seq_type): raise self.failureException('First sequence is not a %s: %s' diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 2cdc3da..368a7d5 100644 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -1332,7 +1332,7 @@ that this python file is installed to the same path as the library (or its /usr/lib/debug/usr/lib/libpython2.6.so.1.0.debug-gdb.py """ def register (obj): - if obj == None: + if obj is None: obj = gdb # Wire up the pretty-printer diff --git a/Tools/scripts/texi2html.py b/Tools/scripts/texi2html.py index af2147a..9983528 100755 --- a/Tools/scripts/texi2html.py +++ b/Tools/scripts/texi2html.py @@ -319,7 +319,7 @@ class TexinfoParser: # Start saving text in a buffer instead of writing it to a file def startsaving(self): - if self.savetext != None: + if self.savetext is not None: self.savestack.append(self.savetext) # print '*** Recursively saving text, expect trouble' self.savetext = '' @@ -341,7 +341,7 @@ class TexinfoParser: except: print(args) raise TypeError - if self.savetext != None: + if self.savetext is not None: self.savetext = self.savetext + text elif self.nodefp: self.nodefp.write(text) @@ -350,7 +350,7 @@ class TexinfoParser: # Complete the current node -- write footnotes and close file def endnode(self): - if self.savetext != None: + if self.savetext is not None: print('*** Still saving text at end of node') dummy = self.collectsavings() if self.footnotes: @@ -804,7 +804,7 @@ class TexinfoParser: def close_i(self): self.write('') def open_footnote(self): - # if self.savetext <> None: + # if self.savetext is not None: # print '*** Recursive footnote -- expect weirdness' id = len(self.footnotes) + 1 self.write(self.FN_SOURCE_PATTERN % {'id': repr(id)}) @@ -1442,7 +1442,7 @@ class TexinfoParser: else: # some other character, e.g. '-' args = self.itemarg + ' ' + args - if self.itemnumber != None: + if self.itemnumber is not None: args = self.itemnumber + '. ' + args self.itemnumber = increment(self.itemnumber) if self.stack and self.stack[-1] == 'table': -- cgit v0.12