Skip to content

Commit ae1e421

Browse files
author
georg.brandl
committed
Make use of new str.startswith/endswith semantics.
Occurences in email and compiler were ignored due to backwards compat requirements. git-svn-id: http://svn.python.org/projects/python/trunk@46805 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent a3921d6 commit ae1e421

11 files changed

+14
-20
lines changed

Lib/_MozillaCookieJar.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ def _really_load(self, f, filename, ignore_discard, ignore_expires):
6363
if line.endswith("\n"): line = line[:-1]
6464

6565
# skip comments and blank lines XXX what is $ for?
66-
if (line.strip().startswith("#") or
67-
line.strip().startswith("$") or
66+
if (line.strip().startswith(("#", "$")) or
6867
line.strip() == ""):
6968
continue
7069

Lib/difflib.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1422,8 +1422,7 @@ def _line_iterator():
14221422
num_blanks_pending -= 1
14231423
yield _make_line(lines,'-',0), None, True
14241424
continue
1425-
elif s.startswith('--?+') or s.startswith('--+') or \
1426-
s.startswith('- '):
1425+
elif s.startswith(('--?+', '--+', '- ')):
14271426
# in delete block and see a intraline change or unchanged line
14281427
# coming: yield the delete line and then blanks
14291428
from_line,to_line = _make_line(lines,'-',0), None
@@ -1447,7 +1446,7 @@ def _line_iterator():
14471446
num_blanks_pending += 1
14481447
yield None, _make_line(lines,'+',1), True
14491448
continue
1450-
elif s.startswith('+ ') or s.startswith('+-'):
1449+
elif s.startswith(('+ ', '+-')):
14511450
# will be leaving an add block: yield blanks then add line
14521451
from_line, to_line = None, _make_line(lines,'+',1)
14531452
num_blanks_to_yield,num_blanks_pending = num_blanks_pending+1,0

Lib/idlelib/EditorWindow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def reset_help_menu_entries(self):
649649
def __extra_help_callback(self, helpfile):
650650
"Create a callback with the helpfile value frozen at definition time"
651651
def display_extra_help(helpfile=helpfile):
652-
if not (helpfile.startswith('www') or helpfile.startswith('http')):
652+
if not helpfile.startswith(('www', 'http')):
653653
url = os.path.normpath(helpfile)
654654
if sys.platform[:3] == 'win':
655655
os.startfile(helpfile)

Lib/idlelib/configHandler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def RemoveKeyBindNames(self,extnNameList):
406406
names=extnNameList
407407
kbNameIndicies=[]
408408
for name in names:
409-
if name.endswith('_bindings') or name.endswith('_cfgBindings'):
409+
if name.endswith(('_bindings', '_cfgBindings')):
410410
kbNameIndicies.append(names.index(name))
411411
kbNameIndicies.sort()
412412
kbNameIndicies.reverse()

Lib/idlelib/configHelpSourceEdit.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def PathOk(self):
127127
parent=self)
128128
self.entryPath.focus_set()
129129
pathOk = False
130-
elif path.startswith('www.') or path.startswith('http'):
130+
elif path.startswith(('www.', 'http')):
131131
pass
132132
else:
133133
if path[:5] == 'file:':
@@ -146,8 +146,7 @@ def Ok(self, event=None):
146146
self.path.get().strip())
147147
if sys.platform == 'darwin':
148148
path = self.result[1]
149-
if (path.startswith('www') or path.startswith('file:')
150-
or path.startswith('http:')):
149+
if path.startswith(('www', 'file:', 'http:')):
151150
pass
152151
else:
153152
# Mac Safari insists on using the URI form for local files

Lib/test/test_compiler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def testDefaultArgs(self):
6262
def testLineNo(self):
6363
# Test that all nodes except Module have a correct lineno attribute.
6464
filename = __file__
65-
if filename.endswith(".pyc") or filename.endswith(".pyo"):
65+
if filename.endswith((".pyc", ".pyo")):
6666
filename = filename[:-1]
6767
tree = compiler.parseFile(filename)
6868
self.check_lineno(tree)

Lib/test/test_inspect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# isdatadescriptor
1616

1717
modfile = mod.__file__
18-
if modfile.endswith('c') or modfile.endswith('o'):
18+
if modfile.endswith(('c', 'o')):
1919
modfile = modfile[:-1]
2020

2121
import __builtin__

Lib/test/test_tcl.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,8 @@ def testLoadTkFailure(self):
130130
import os
131131
old_display = None
132132
import sys
133-
if (sys.platform.startswith('win') or
134-
sys.platform.startswith('darwin') or
135-
sys.platform.startswith('cygwin')):
136-
return # no failure possible on windows?
133+
if sys.platform.startswith(('win', 'darwin', 'cygwin')):
134+
return # no failure possible on windows?
137135
if 'DISPLAY' in os.environ:
138136
old_display = os.environ['DISPLAY']
139137
del os.environ['DISPLAY']

Lib/trace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def write_results(self, show_missing=True, summary=False, coverdir=None):
285285
if filename == "<string>":
286286
continue
287287

288-
if filename.endswith(".pyc") or filename.endswith(".pyo"):
288+
if filename.endswith((".pyc", ".pyo")):
289289
filename = filename[:-1]
290290

291291
if coverdir is None:

Lib/warnings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def warn(message, category=None, stacklevel=1):
4646
filename = globals.get('__file__')
4747
if filename:
4848
fnl = filename.lower()
49-
if fnl.endswith(".pyc") or fnl.endswith(".pyo"):
49+
if fnl.endswith((".pyc", ".pyo")):
5050
filename = filename[:-1]
5151
else:
5252
if module == "__main__":

Lib/webbrowser.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ def _synthesize(browser, update_tryorder=1):
9898
if sys.platform[:3] == "win":
9999
def _isexecutable(cmd):
100100
cmd = cmd.lower()
101-
if os.path.isfile(cmd) and (cmd.endswith(".exe") or
102-
cmd.endswith(".bat")):
101+
if os.path.isfile(cmd) and cmd.endswith((".exe", ".bat")):
103102
return True
104103
for ext in ".exe", ".bat":
105104
if os.path.isfile(cmd + ext):

0 commit comments

Comments
 (0)