Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbecd93

Browse files
committed
Replace list of constants with tuples of constants.
1 parent 07ead17 commit dbecd93

11 files changed

Lines changed: 29 additions & 29 deletions

File tree

Lib/cgitb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def reader(lnum=[lnum]):
146146
if name in done: continue
147147
done[name] = 1
148148
if value is not __UNDEF__:
149-
if where in ['global', 'builtin']:
149+
if where in ('global', 'builtin'):
150150
name = ('<em>%s</em> ' % where) + strong(name)
151151
elif where == 'local':
152152
name = strong(name)

Lib/cookielib.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,12 +783,12 @@ def __str__(self):
783783

784784
def __repr__(self):
785785
args = []
786-
for name in ["version", "name", "value",
786+
for name in ("version", "name", "value",
787787
"port", "port_specified",
788788
"domain", "domain_specified", "domain_initial_dot",
789789
"path", "path_specified",
790790
"secure", "expires", "discard", "comment", "comment_url",
791-
]:
791+
):
792792
attr = getattr(self, name)
793793
args.append("%s=%s" % (name, repr(attr)))
794794
args.append("rest=%s" % repr(self._rest))
@@ -981,9 +981,9 @@ def set_ok_domain(self, cookie, request):
981981
if j == 0: # domain like .foo.bar
982982
tld = domain[i+1:]
983983
sld = domain[j+1:i]
984-
if (sld.lower() in [
984+
if (sld.lower() in (
985985
"co", "ac",
986-
"com", "edu", "org", "net", "gov", "mil", "int"] and
986+
"com", "edu", "org", "net", "gov", "mil", "int") and
987987
len(tld) == 2):
988988
# domain like .co.uk
989989
debug(" country-code second level domain %s", domain)
@@ -1415,7 +1415,7 @@ def _normalized_cookie_tuples(self, attrs_set):
14151415
v = self._now + v
14161416
if (k in value_attrs) or (k in boolean_attrs):
14171417
if (v is None and
1418-
k not in ["port", "comment", "commenturl"]):
1418+
k not in ("port", "comment", "commenturl")):
14191419
debug(" missing value for %s attribute" % k)
14201420
bad_cookie = True
14211421
break

Lib/decimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def __new__(cls, value="0", context=None):
515515
if isinstance(value, (list,tuple)):
516516
if len(value) != 3:
517517
raise ValueError, 'Invalid arguments'
518-
if value[0] not in [0,1]:
518+
if value[0] not in (0,1):
519519
raise ValueError, 'Invalid sign'
520520
for digit in value[1]:
521521
if not isinstance(digit, (int,long)) or digit < 0:

Lib/inspect.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def getmodulename(path):
346346
def getsourcefile(object):
347347
"""Return the Python source file an object was defined in, if it exists."""
348348
filename = getfile(object)
349-
if string.lower(filename[-4:]) in ['.pyc', '.pyo']:
349+
if string.lower(filename[-4:]) in ('.pyc', '.pyo'):
350350
filename = filename[:-4] + '.py'
351351
for suffix, mode, kind in imp.get_suffixes():
352352
if 'b' in mode and string.lower(filename[-len(suffix):]) == suffix:
@@ -453,7 +453,7 @@ def getcomments(object):
453453
# Look for a comment block at the top of the file.
454454
start = 0
455455
if lines and lines[0][:2] == '#!': start = 1
456-
while start < len(lines) and string.strip(lines[start]) in ['', '#']:
456+
while start < len(lines) and string.strip(lines[start]) in ('', '#'):
457457
start = start + 1
458458
if start < len(lines) and lines[start][:1] == '#':
459459
comments = []
@@ -621,7 +621,7 @@ def getargs(co):
621621

622622
# The following acrobatics are for anonymous (tuple) arguments.
623623
for i in range(nargs):
624-
if args[i][:1] in ['', '.']:
624+
if args[i][:1] in ('', '.'):
625625
stack, remain, count = [], [], []
626626
while step < len(code):
627627
op = ord(code[step])
@@ -630,7 +630,7 @@ def getargs(co):
630630
opname = dis.opname[op]
631631
value = ord(code[step]) + ord(code[step+1])*256
632632
step = step + 2
633-
if opname in ['UNPACK_TUPLE', 'UNPACK_SEQUENCE']:
633+
if opname in ('UNPACK_TUPLE', 'UNPACK_SEQUENCE'):
634634
remain.append(value)
635635
count.append(value)
636636
elif opname == 'STORE_FAST':
@@ -696,7 +696,7 @@ def joinseq(seq):
696696

697697
def strseq(object, convert, join=joinseq):
698698
"""Recursively walk a sequence, stringifying each element."""
699-
if type(object) in [types.ListType, types.TupleType]:
699+
if type(object) in (list, tuple):
700700
return join(map(lambda o, c=convert, j=join: strseq(o, c, j), object))
701701
else:
702702
return convert(object)

Lib/mhlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,11 +982,11 @@ def do(s): print s; print eval(s)
982982
context = mh.getcontext()
983983
f = mh.openfolder(context)
984984
do('f.getcurrent()')
985-
for seq in ['first', 'last', 'cur', '.', 'prev', 'next',
985+
for seq in ('first', 'last', 'cur', '.', 'prev', 'next',
986986
'first:3', 'last:3', 'cur:3', 'cur:-3',
987987
'prev:3', 'next:3',
988988
'1:3', '1:-3', '100:3', '100:-3', '10000:3', '10000:-3',
989-
'all']:
989+
'all'):
990990
try:
991991
do('f.parsesequence(%r)' % (seq,))
992992
except Error, msg:

Lib/posixfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def lock(self, how, *args):
182182
'freebsd6', 'bsdos2', 'bsdos3', 'bsdos4'):
183183
flock = struct.pack('lxxxxlxxxxlhh', \
184184
l_start, l_len, os.getpid(), l_type, l_whence)
185-
elif sys.platform in ['aix3', 'aix4']:
185+
elif sys.platform in ('aix3', 'aix4'):
186186
flock = struct.pack('hhlllii', \
187187
l_type, l_whence, l_start, l_len, 0, 0, 0)
188188
else:
@@ -198,7 +198,7 @@ def lock(self, how, *args):
198198
'bsdos2', 'bsdos3', 'bsdos4'):
199199
l_start, l_len, l_pid, l_type, l_whence = \
200200
struct.unpack('lxxxxlxxxxlhh', flock)
201-
elif sys.platform in ['aix3', 'aix4']:
201+
elif sys.platform in ('aix3', 'aix4'):
202202
l_type, l_whence, l_start, l_len, l_sysid, l_pid, l_vfs = \
203203
struct.unpack('hhlllii', flock)
204204
elif sys.platform == "linux2":

Lib/pydoc.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ def _split_list(s, predicate):
153153
def visiblename(name, all=None):
154154
"""Decide whether to show documentation on a variable."""
155155
# Certain special names are redundant.
156-
if name in ['__builtins__', '__doc__', '__file__', '__path__',
157-
'__module__', '__name__', '__slots__']: return 0
156+
if name in ('__builtins__', '__doc__', '__file__', '__path__',
157+
'__module__', '__name__', '__slots__'): return 0
158158
# Private names are hidden, but special names are displayed.
159159
if name.startswith('__') and name.endswith('__'): return 1
160160
if all is not None:
@@ -176,7 +176,7 @@ def fixup((name, kind, cls, value)):
176176
def ispackage(path):
177177
"""Guess whether a path refers to a package directory."""
178178
if os.path.isdir(path):
179-
for ext in ['.py', '.pyc', '.pyo']:
179+
for ext in ('.py', '.pyc', '.pyo'):
180180
if os.path.isfile(os.path.join(path, '__init__' + ext)):
181181
return True
182182
return False
@@ -1298,12 +1298,12 @@ def getpager():
12981298
return plainpager
12991299
if not sys.stdin.isatty() or not sys.stdout.isatty():
13001300
return plainpager
1301-
if os.environ.get('TERM') in ['dumb', 'emacs']:
1301+
if os.environ.get('TERM') in ('dumb', 'emacs'):
13021302
return plainpager
13031303
if 'PAGER' in os.environ:
13041304
if sys.platform == 'win32': # pipes completely broken in Windows
13051305
return lambda text: tempfilepager(plain(text), os.environ['PAGER'])
1306-
elif os.environ.get('TERM') in ['dumb', 'emacs']:
1306+
elif os.environ.get('TERM') in ('dumb', 'emacs'):
13071307
return lambda text: pipepager(plain(text), os.environ['PAGER'])
13081308
else:
13091309
return lambda text: pipepager(text, os.environ['PAGER'])
@@ -1369,14 +1369,14 @@ def ttypager(text):
13691369
sys.stdout.flush()
13701370
c = getchar()
13711371

1372-
if c in ['q', 'Q']:
1372+
if c in ('q', 'Q'):
13731373
sys.stdout.write('\r \r')
13741374
break
1375-
elif c in ['\r', '\n']:
1375+
elif c in ('\r', '\n'):
13761376
sys.stdout.write('\r \r' + lines[r] + '\n')
13771377
r = r + 1
13781378
continue
1379-
if c in ['b', 'B', '\x1b']:
1379+
if c in ('b', 'B', '\x1b'):
13801380
r = r - inc - inc
13811381
if r < 0: r = 0
13821382
sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n')
@@ -1646,7 +1646,7 @@ def interact(self):
16461646
except (KeyboardInterrupt, EOFError):
16471647
break
16481648
request = strip(replace(request, '"', '', "'", ''))
1649-
if lower(request) in ['q', 'quit']: break
1649+
if lower(request) in ('q', 'quit'): break
16501650
self.help(request)
16511651

16521652
def getline(self, prompt):

Lib/smtplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def encode_plain(user, password):
578578
(code, resp) = self.docmd(encode_base64(password, eol=""))
579579
elif authmethod is None:
580580
raise SMTPException("No suitable authentication method found.")
581-
if code not in [235, 503]:
581+
if code not in (235, 503):
582582
# 235 == 'Authentication successful'
583583
# 503 == 'Error: already authenticated'
584584
raise SMTPAuthenticationError(code, resp)

Lib/urllib2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def _open(self, req, data=None):
384384
'unknown_open', req)
385385

386386
def error(self, proto, *args):
387-
if proto in ['http', 'https']:
387+
if proto in ('http', 'https'):
388388
# XXX http[s] protocols are special-cased
389389
dict = self.handle_error['http'] # https is not different than http
390390
proto = args[2] # YUCK!

Lib/warnings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def _getaction(action):
216216
if not action:
217217
return "default"
218218
if action == "all": return "always" # Alias
219-
for a in ['default', 'always', 'ignore', 'module', 'once', 'error']:
219+
for a in ('default', 'always', 'ignore', 'module', 'once', 'error'):
220220
if a.startswith(action):
221221
return a
222222
raise _OptionError("invalid action: %r" % (action,))

0 commit comments

Comments
 (0)