Skip to content

Commit 10ff706

Browse files
committed
Replaced boolean tests with is None.
1 parent f13eb55 commit 10ff706

5 files changed

Lines changed: 14 additions & 14 deletions

File tree

Lib/telnetlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def __init__(self, host=None, port=0):
186186
self.cookedq = ''
187187
self.eof = 0
188188
self.option_callback = None
189-
if host:
189+
if host is not None:
190190
self.open(host, port)
191191

192192
def open(self, host, port=0):

Lib/traceback.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def _print(file, str='', terminator='\n'):
1616
def print_list(extracted_list, file=None):
1717
"""Print the list of tuples as returned by extract_tb() or
1818
extract_stack() as a formatted stack trace to the given file."""
19-
if not file:
19+
if file is None:
2020
file = sys.stderr
2121
for filename, lineno, name, line in extracted_list:
2222
_print(file,
@@ -51,7 +51,7 @@ def print_tb(tb, limit=None, file=None):
5151
'file' should be an open file or file-like object with a write()
5252
method.
5353
"""
54-
if not file:
54+
if file is None:
5555
file = sys.stderr
5656
if limit is None:
5757
if hasattr(sys, 'tracebacklimit'):
@@ -116,7 +116,7 @@ def print_exception(etype, value, tb, limit=None, file=None):
116116
occurred with a caret on the next line indicating the approximate
117117
position of the error.
118118
"""
119-
if not file:
119+
if file is None:
120120
file = sys.stderr
121121
if tb:
122122
_print(file, 'Traceback (most recent call last):')
@@ -203,7 +203,7 @@ def print_exc(limit=None, file=None):
203203
"""Shorthand for 'print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file)'.
204204
(In fact, it uses sys.exc_info() to retrieve the same information
205205
in a thread-safe way.)"""
206-
if not file:
206+
if file is None:
207207
file = sys.stderr
208208
try:
209209
etype, value, tb = sys.exc_info()
@@ -214,7 +214,7 @@ def print_exc(limit=None, file=None):
214214
def print_last(limit=None, file=None):
215215
"""This is a shorthand for 'print_exception(sys.last_type,
216216
sys.last_value, sys.last_traceback, limit, file)'."""
217-
if not file:
217+
if file is None:
218218
file = sys.stderr
219219
print_exception(sys.last_type, sys.last_value, sys.last_traceback,
220220
limit, file)

Lib/urllib.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def retrieve(self, url, filename=None, reporthook=None, data=None):
203203
if self.tempcache and url in self.tempcache:
204204
return self.tempcache[url]
205205
type, url1 = splittype(url)
206-
if not filename and (not type or type == 'file'):
206+
if filename is None and (not type or type == 'file'):
207207
try:
208208
fp = self.open_local_file(url1)
209209
hdrs = fp.info()
@@ -662,23 +662,23 @@ def prompt_user_passwd(self, host, realm):
662662
def localhost():
663663
"""Return the IP address of the magic hostname 'localhost'."""
664664
global _localhost
665-
if not _localhost:
665+
if _localhost is None:
666666
_localhost = socket.gethostbyname('localhost')
667667
return _localhost
668668

669669
_thishost = None
670670
def thishost():
671671
"""Return the IP address of the current host."""
672672
global _thishost
673-
if not _thishost:
673+
if _thishost is None:
674674
_thishost = socket.gethostbyname(socket.gethostname())
675675
return _thishost
676676

677677
_ftperrors = None
678678
def ftperrors():
679679
"""Return the set of errors raised by the FTP class."""
680680
global _ftperrors
681-
if not _ftperrors:
681+
if _ftperrors is None:
682682
import ftplib
683683
_ftperrors = ftplib.all_errors
684684
return _ftperrors
@@ -687,7 +687,7 @@ def ftperrors():
687687
def noheaders():
688688
"""Return an empty mimetools.Message object."""
689689
global _noheaders
690-
if not _noheaders:
690+
if _noheaders is None:
691691
import mimetools
692692
import StringIO
693693
_noheaders = mimetools.Message(StringIO.StringIO(), 0)

Lib/webbrowser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def register(name, klass, instance=None):
1717

1818
def get(using=None):
1919
"""Return a browser launcher instance appropriate for the environment."""
20-
if using:
20+
if using is not None:
2121
alternatives = [using]
2222
else:
2323
alternatives = _tryorder

Lib/xmlrpclib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ def dumps(params, methodname=None, methodresponse=None, encoding=None):
755755
elif methodresponse and isinstance(params, TupleType):
756756
assert len(params) == 1, "response tuple must be a singleton"
757757

758-
if not encoding:
758+
if encoding is None:
759759
encoding = "utf-8"
760760

761761
m = Marshaller(encoding)
@@ -767,7 +767,7 @@ def dumps(params, methodname=None, methodresponse=None, encoding=None):
767767
xmlheader = "<?xml version='1.0'?>\n" # utf-8 is default
768768

769769
# standard XML-RPC wrappings
770-
if methodname:
770+
if methodname is not None:
771771
# a method call
772772
if not isinstance(methodname, StringType):
773773
methodname = methodname.encode(encoding)

0 commit comments

Comments
 (0)