mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-44712: Replace "type(literal)" with corresponding builtin types (GH-27294)
I suppose it is a remnants of very old code written when str, int, list, dict, etc were functions and not classes.
This commit is contained in:
parent
c826867b7c
commit
3680ebed7f
19 changed files with 41 additions and 39 deletions
|
@ -74,7 +74,7 @@ def lookup(name, frame, locals):
|
||||||
return 'global', frame.f_globals[name]
|
return 'global', frame.f_globals[name]
|
||||||
if '__builtins__' in frame.f_globals:
|
if '__builtins__' in frame.f_globals:
|
||||||
builtins = frame.f_globals['__builtins__']
|
builtins = frame.f_globals['__builtins__']
|
||||||
if type(builtins) is type({}):
|
if isinstance(builtins, dict):
|
||||||
if name in builtins:
|
if name in builtins:
|
||||||
return 'builtin', builtins[name]
|
return 'builtin', builtins[name]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -428,7 +428,7 @@ class Sniffer:
|
||||||
# on whether it's a header
|
# on whether it's a header
|
||||||
hasHeader = 0
|
hasHeader = 0
|
||||||
for col, colType in columnTypes.items():
|
for col, colType in columnTypes.items():
|
||||||
if type(colType) == type(0): # it's a length
|
if isinstance(colType, int): # it's a length
|
||||||
if len(header[col]) != colType:
|
if len(header[col]) != colType:
|
||||||
hasHeader += 1
|
hasHeader += 1
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -46,7 +46,7 @@ controlnames = [
|
||||||
]
|
]
|
||||||
|
|
||||||
def _ctoi(c):
|
def _ctoi(c):
|
||||||
if type(c) == type(""):
|
if isinstance(c, str):
|
||||||
return ord(c)
|
return ord(c)
|
||||||
else:
|
else:
|
||||||
return c
|
return c
|
||||||
|
@ -69,19 +69,19 @@ def isctrl(c): return 0 <= _ctoi(c) < 32
|
||||||
def ismeta(c): return _ctoi(c) > 127
|
def ismeta(c): return _ctoi(c) > 127
|
||||||
|
|
||||||
def ascii(c):
|
def ascii(c):
|
||||||
if type(c) == type(""):
|
if isinstance(c, str):
|
||||||
return chr(_ctoi(c) & 0x7f)
|
return chr(_ctoi(c) & 0x7f)
|
||||||
else:
|
else:
|
||||||
return _ctoi(c) & 0x7f
|
return _ctoi(c) & 0x7f
|
||||||
|
|
||||||
def ctrl(c):
|
def ctrl(c):
|
||||||
if type(c) == type(""):
|
if isinstance(c, str):
|
||||||
return chr(_ctoi(c) & 0x1f)
|
return chr(_ctoi(c) & 0x1f)
|
||||||
else:
|
else:
|
||||||
return _ctoi(c) & 0x1f
|
return _ctoi(c) & 0x1f
|
||||||
|
|
||||||
def alt(c):
|
def alt(c):
|
||||||
if type(c) == type(""):
|
if isinstance(c, str):
|
||||||
return chr(_ctoi(c) | 0x80)
|
return chr(_ctoi(c) | 0x80)
|
||||||
else:
|
else:
|
||||||
return _ctoi(c) | 0x80
|
return _ctoi(c) | 0x80
|
||||||
|
|
|
@ -260,7 +260,7 @@ Your selection [default 1]: ''', log.INFO)
|
||||||
body = io.StringIO()
|
body = io.StringIO()
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
# handle multiple entries for the same name
|
# handle multiple entries for the same name
|
||||||
if type(value) not in (type([]), type( () )):
|
if not isinstance(value, (list, tuple)):
|
||||||
value = [value]
|
value = [value]
|
||||||
for value in value:
|
for value in value:
|
||||||
value = str(value)
|
value = str(value)
|
||||||
|
|
|
@ -561,7 +561,7 @@ class FTP:
|
||||||
LIST command. (This *should* only be used for a pathname.)'''
|
LIST command. (This *should* only be used for a pathname.)'''
|
||||||
cmd = 'LIST'
|
cmd = 'LIST'
|
||||||
func = None
|
func = None
|
||||||
if args[-1:] and type(args[-1]) != type(''):
|
if args[-1:] and not isinstance(args[-1], str):
|
||||||
args, func = args[:-1], args[-1]
|
args, func = args[:-1], args[-1]
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if arg:
|
if arg:
|
||||||
|
|
|
@ -81,7 +81,7 @@ def getopt(args, shortopts, longopts = []):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
opts = []
|
opts = []
|
||||||
if type(longopts) == type(""):
|
if isinstance(longopts, str):
|
||||||
longopts = [longopts]
|
longopts = [longopts]
|
||||||
else:
|
else:
|
||||||
longopts = list(longopts)
|
longopts = list(longopts)
|
||||||
|
|
|
@ -43,7 +43,7 @@ def transform_children(child_dict, modname=None):
|
||||||
# If obj.name != key, it has already been suffixed.
|
# If obj.name != key, it has already been suffixed.
|
||||||
supers = []
|
supers = []
|
||||||
for sup in obj.super:
|
for sup in obj.super:
|
||||||
if type(sup) is type(''):
|
if isinstance(sup, str):
|
||||||
sname = sup
|
sname = sup
|
||||||
else:
|
else:
|
||||||
sname = sup.name
|
sname = sup.name
|
||||||
|
|
|
@ -72,7 +72,7 @@ NT_OFFSET = 256
|
||||||
|
|
||||||
tok_name = {}
|
tok_name = {}
|
||||||
for _name, _value in list(globals().items()):
|
for _name, _value in list(globals().items()):
|
||||||
if type(_value) is type(0):
|
if isinstance(_value, int):
|
||||||
tok_name[_value] = _name
|
tok_name[_value] = _name
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ class _PlistParser:
|
||||||
|
|
||||||
def add_object(self, value):
|
def add_object(self, value):
|
||||||
if self.current_key is not None:
|
if self.current_key is not None:
|
||||||
if not isinstance(self.stack[-1], type({})):
|
if not isinstance(self.stack[-1], dict):
|
||||||
raise ValueError("unexpected element at line %d" %
|
raise ValueError("unexpected element at line %d" %
|
||||||
self.parser.CurrentLineNumber)
|
self.parser.CurrentLineNumber)
|
||||||
self.stack[-1][self.current_key] = value
|
self.stack[-1][self.current_key] = value
|
||||||
|
@ -208,7 +208,7 @@ class _PlistParser:
|
||||||
# this is the root object
|
# this is the root object
|
||||||
self.root = value
|
self.root = value
|
||||||
else:
|
else:
|
||||||
if not isinstance(self.stack[-1], type([])):
|
if not isinstance(self.stack[-1], list):
|
||||||
raise ValueError("unexpected element at line %d" %
|
raise ValueError("unexpected element at line %d" %
|
||||||
self.parser.CurrentLineNumber)
|
self.parser.CurrentLineNumber)
|
||||||
self.stack[-1].append(value)
|
self.stack[-1].append(value)
|
||||||
|
@ -232,7 +232,7 @@ class _PlistParser:
|
||||||
self.stack.pop()
|
self.stack.pop()
|
||||||
|
|
||||||
def end_key(self):
|
def end_key(self):
|
||||||
if self.current_key or not isinstance(self.stack[-1], type({})):
|
if self.current_key or not isinstance(self.stack[-1], dict):
|
||||||
raise ValueError("unexpected key at line %d" %
|
raise ValueError("unexpected key at line %d" %
|
||||||
self.parser.CurrentLineNumber)
|
self.parser.CurrentLineNumber)
|
||||||
self.current_key = self.get_data()
|
self.current_key = self.get_data()
|
||||||
|
|
|
@ -162,7 +162,7 @@ def _copy(master_fd, master_read=_read, stdin_read=_read):
|
||||||
|
|
||||||
def spawn(argv, master_read=_read, stdin_read=_read):
|
def spawn(argv, master_read=_read, stdin_read=_read):
|
||||||
"""Create a spawned process."""
|
"""Create a spawned process."""
|
||||||
if type(argv) == type(''):
|
if isinstance(argv, str):
|
||||||
argv = (argv,)
|
argv = (argv,)
|
||||||
sys.audit('pty.spawn', argv)
|
sys.audit('pty.spawn', argv)
|
||||||
|
|
||||||
|
|
12
Lib/pydoc.py
12
Lib/pydoc.py
|
@ -727,7 +727,7 @@ class HTMLDoc(Doc):
|
||||||
"""Produce HTML for a class tree as given by inspect.getclasstree()."""
|
"""Produce HTML for a class tree as given by inspect.getclasstree()."""
|
||||||
result = ''
|
result = ''
|
||||||
for entry in tree:
|
for entry in tree:
|
||||||
if type(entry) is type(()):
|
if isinstance(entry, tuple):
|
||||||
c, bases = entry
|
c, bases = entry
|
||||||
result = result + '<dt class="heading-text">'
|
result = result + '<dt class="heading-text">'
|
||||||
result = result + self.classlink(c, modname)
|
result = result + self.classlink(c, modname)
|
||||||
|
@ -737,7 +737,7 @@ class HTMLDoc(Doc):
|
||||||
parents.append(self.classlink(base, modname))
|
parents.append(self.classlink(base, modname))
|
||||||
result = result + '(' + ', '.join(parents) + ')'
|
result = result + '(' + ', '.join(parents) + ')'
|
||||||
result = result + '\n</dt>'
|
result = result + '\n</dt>'
|
||||||
elif type(entry) is type([]):
|
elif isinstance(entry, list):
|
||||||
result = result + '<dd>\n%s</dd>\n' % self.formattree(
|
result = result + '<dd>\n%s</dd>\n' % self.formattree(
|
||||||
entry, modname, c)
|
entry, modname, c)
|
||||||
return '<dl>\n%s</dl>\n' % result
|
return '<dl>\n%s</dl>\n' % result
|
||||||
|
@ -1190,14 +1190,14 @@ class TextDoc(Doc):
|
||||||
"""Render in text a class tree as returned by inspect.getclasstree()."""
|
"""Render in text a class tree as returned by inspect.getclasstree()."""
|
||||||
result = ''
|
result = ''
|
||||||
for entry in tree:
|
for entry in tree:
|
||||||
if type(entry) is type(()):
|
if isinstance(entry, tuple):
|
||||||
c, bases = entry
|
c, bases = entry
|
||||||
result = result + prefix + classname(c, modname)
|
result = result + prefix + classname(c, modname)
|
||||||
if bases and bases != (parent,):
|
if bases and bases != (parent,):
|
||||||
parents = (classname(c, modname) for c in bases)
|
parents = (classname(c, modname) for c in bases)
|
||||||
result = result + '(%s)' % ', '.join(parents)
|
result = result + '(%s)' % ', '.join(parents)
|
||||||
result = result + '\n'
|
result = result + '\n'
|
||||||
elif type(entry) is type([]):
|
elif isinstance(entry, list):
|
||||||
result = result + self.formattree(
|
result = result + self.formattree(
|
||||||
entry, modname, c, prefix + ' ')
|
entry, modname, c, prefix + ' ')
|
||||||
return result
|
return result
|
||||||
|
@ -2044,7 +2044,7 @@ has the same effect as typing a particular string at the help> prompt.
|
||||||
return self.input.readline()
|
return self.input.readline()
|
||||||
|
|
||||||
def help(self, request):
|
def help(self, request):
|
||||||
if type(request) is type(''):
|
if isinstance(request, str):
|
||||||
request = request.strip()
|
request = request.strip()
|
||||||
if request == 'keywords': self.listkeywords()
|
if request == 'keywords': self.listkeywords()
|
||||||
elif request == 'symbols': self.listsymbols()
|
elif request == 'symbols': self.listsymbols()
|
||||||
|
@ -2129,7 +2129,7 @@ module "pydoc_data.topics" could not be found.
|
||||||
if not target:
|
if not target:
|
||||||
self.output.write('no documentation found for %s\n' % repr(topic))
|
self.output.write('no documentation found for %s\n' % repr(topic))
|
||||||
return
|
return
|
||||||
if type(target) is type(''):
|
if isinstance(target, str):
|
||||||
return self.showtopic(target, more_xrefs)
|
return self.showtopic(target, more_xrefs)
|
||||||
|
|
||||||
label, xrefs = target
|
label, xrefs = target
|
||||||
|
|
|
@ -160,7 +160,7 @@ def _write_u32(file, x):
|
||||||
class Au_read:
|
class Au_read:
|
||||||
|
|
||||||
def __init__(self, f):
|
def __init__(self, f):
|
||||||
if type(f) == type(''):
|
if isinstance(f, str):
|
||||||
import builtins
|
import builtins
|
||||||
f = builtins.open(f, 'rb')
|
f = builtins.open(f, 'rb')
|
||||||
self._opened = True
|
self._opened = True
|
||||||
|
@ -312,7 +312,7 @@ class Au_read:
|
||||||
class Au_write:
|
class Au_write:
|
||||||
|
|
||||||
def __init__(self, f):
|
def __init__(self, f):
|
||||||
if type(f) == type(''):
|
if isinstance(f, str):
|
||||||
import builtins
|
import builtins
|
||||||
f = builtins.open(f, 'wb')
|
f = builtins.open(f, 'wb')
|
||||||
self._opened = True
|
self._opened = True
|
||||||
|
|
|
@ -6,6 +6,9 @@ from test.pickletester import ExtensionSaver
|
||||||
class C:
|
class C:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def pickle_C(c):
|
||||||
|
return C, ()
|
||||||
|
|
||||||
|
|
||||||
class WithoutSlots(object):
|
class WithoutSlots(object):
|
||||||
pass
|
pass
|
||||||
|
@ -32,16 +35,15 @@ class WithInherited(WithSingleString):
|
||||||
class CopyRegTestCase(unittest.TestCase):
|
class CopyRegTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_class(self):
|
def test_class(self):
|
||||||
self.assertRaises(TypeError, copyreg.pickle,
|
copyreg.pickle(C, pickle_C)
|
||||||
C, None, None)
|
|
||||||
|
|
||||||
def test_noncallable_reduce(self):
|
def test_noncallable_reduce(self):
|
||||||
self.assertRaises(TypeError, copyreg.pickle,
|
self.assertRaises(TypeError, copyreg.pickle,
|
||||||
type(1), "not a callable")
|
C, "not a callable")
|
||||||
|
|
||||||
def test_noncallable_constructor(self):
|
def test_noncallable_constructor(self):
|
||||||
self.assertRaises(TypeError, copyreg.pickle,
|
self.assertRaises(TypeError, copyreg.pickle,
|
||||||
type(1), int, "not a callable")
|
C, pickle_C, "not a callable")
|
||||||
|
|
||||||
def test_bool(self):
|
def test_bool(self):
|
||||||
import copy
|
import copy
|
||||||
|
|
|
@ -426,7 +426,7 @@ class ClassPropertiesAndMethods(unittest.TestCase):
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return self.get(key, 0)
|
return self.get(key, 0)
|
||||||
def __setitem__(self_local, key, value):
|
def __setitem__(self_local, key, value):
|
||||||
self.assertIsInstance(key, type(0))
|
self.assertIsInstance(key, int)
|
||||||
dict.__setitem__(self_local, key, value)
|
dict.__setitem__(self_local, key, value)
|
||||||
def setstate(self, state):
|
def setstate(self, state):
|
||||||
self.state = state
|
self.state = state
|
||||||
|
@ -871,7 +871,7 @@ class ClassPropertiesAndMethods(unittest.TestCase):
|
||||||
self.assertEqual(a.getstate(), 10)
|
self.assertEqual(a.getstate(), 10)
|
||||||
class D(dict, C):
|
class D(dict, C):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
type({}).__init__(self)
|
dict.__init__(self)
|
||||||
C.__init__(self)
|
C.__init__(self)
|
||||||
d = D()
|
d = D()
|
||||||
self.assertEqual(list(d.keys()), [])
|
self.assertEqual(list(d.keys()), [])
|
||||||
|
@ -3288,7 +3288,7 @@ order (MRO) for bases """
|
||||||
cant(True, int)
|
cant(True, int)
|
||||||
cant(2, bool)
|
cant(2, bool)
|
||||||
o = object()
|
o = object()
|
||||||
cant(o, type(1))
|
cant(o, int)
|
||||||
cant(o, type(None))
|
cant(o, type(None))
|
||||||
del o
|
del o
|
||||||
class G(object):
|
class G(object):
|
||||||
|
|
|
@ -203,7 +203,7 @@ class QueryTestCase(unittest.TestCase):
|
||||||
def test_unreadable(self):
|
def test_unreadable(self):
|
||||||
# Not recursive but not readable anyway
|
# Not recursive but not readable anyway
|
||||||
pp = pprint.PrettyPrinter()
|
pp = pprint.PrettyPrinter()
|
||||||
for unreadable in type(3), pprint, pprint.isrecursive:
|
for unreadable in object(), int, pprint, pprint.isrecursive:
|
||||||
# module-level convenience functions
|
# module-level convenience functions
|
||||||
self.assertFalse(pprint.isrecursive(unreadable),
|
self.assertFalse(pprint.isrecursive(unreadable),
|
||||||
"expected not isrecursive for %r" % (unreadable,))
|
"expected not isrecursive for %r" % (unreadable,))
|
||||||
|
|
|
@ -50,10 +50,10 @@ class CreationTestCase(unittest.TestCase):
|
||||||
def testReturnType(self):
|
def testReturnType(self):
|
||||||
# Test return type of gettimeout()
|
# Test return type of gettimeout()
|
||||||
self.sock.settimeout(1)
|
self.sock.settimeout(1)
|
||||||
self.assertEqual(type(self.sock.gettimeout()), type(1.0))
|
self.assertIs(type(self.sock.gettimeout()), float)
|
||||||
|
|
||||||
self.sock.settimeout(3.9)
|
self.sock.settimeout(3.9)
|
||||||
self.assertEqual(type(self.sock.gettimeout()), type(1.0))
|
self.assertIs(type(self.sock.gettimeout()), float)
|
||||||
|
|
||||||
def testTypeCheck(self):
|
def testTypeCheck(self):
|
||||||
# Test type checking by settimeout()
|
# Test type checking by settimeout()
|
||||||
|
|
|
@ -850,9 +850,9 @@ class MultiCallIterator:
|
||||||
|
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
item = self.results[i]
|
item = self.results[i]
|
||||||
if type(item) == type({}):
|
if isinstance(item, dict):
|
||||||
raise Fault(item['faultCode'], item['faultString'])
|
raise Fault(item['faultCode'], item['faultString'])
|
||||||
elif type(item) == type([]):
|
elif isinstance(item, list):
|
||||||
return item[0]
|
return item[0]
|
||||||
else:
|
else:
|
||||||
raise ValueError("unexpected type in multicall result")
|
raise ValueError("unexpected type in multicall result")
|
||||||
|
|
|
@ -1351,7 +1351,7 @@ def buildPython():
|
||||||
build_time_vars = l_dict['build_time_vars']
|
build_time_vars = l_dict['build_time_vars']
|
||||||
vars = {}
|
vars = {}
|
||||||
for k, v in build_time_vars.items():
|
for k, v in build_time_vars.items():
|
||||||
if type(v) == type(''):
|
if isinstance(v, str):
|
||||||
for p in (include_path, lib_path):
|
for p in (include_path, lib_path):
|
||||||
v = v.replace(' ' + p, '')
|
v = v.replace(' ' + p, '')
|
||||||
v = v.replace(p + ' ', '')
|
v = v.replace(p + ' ', '')
|
||||||
|
|
|
@ -70,7 +70,7 @@ emparse_list_list = [
|
||||||
# compile the re's in the list and store them in-place.
|
# compile the re's in the list and store them in-place.
|
||||||
for i in range(len(emparse_list_list)):
|
for i in range(len(emparse_list_list)):
|
||||||
x = emparse_list_list[i]
|
x = emparse_list_list[i]
|
||||||
if type(x) is type(''):
|
if isinstance(x, str):
|
||||||
x = re.compile(x, re.MULTILINE)
|
x = re.compile(x, re.MULTILINE)
|
||||||
else:
|
else:
|
||||||
xl = []
|
xl = []
|
||||||
|
@ -105,7 +105,7 @@ def emparse_list(fp, sub):
|
||||||
emails = []
|
emails = []
|
||||||
reason = None
|
reason = None
|
||||||
for regexp in emparse_list_list:
|
for regexp in emparse_list_list:
|
||||||
if type(regexp) is type(()):
|
if isinstance(regexp, tuple):
|
||||||
res = regexp[0].search(data, 0, from_index)
|
res = regexp[0].search(data, 0, from_index)
|
||||||
if res is not None:
|
if res is not None:
|
||||||
try:
|
try:
|
||||||
|
@ -134,7 +134,7 @@ def emparse_list(fp, sub):
|
||||||
if reason[:15] == 'returned mail: ':
|
if reason[:15] == 'returned mail: ':
|
||||||
reason = reason[15:]
|
reason = reason[15:]
|
||||||
for regexp in emparse_list_reason:
|
for regexp in emparse_list_reason:
|
||||||
if type(regexp) is type(''):
|
if isinstance(regexp, str):
|
||||||
for i in range(len(emails)-1,-1,-1):
|
for i in range(len(emails)-1,-1,-1):
|
||||||
email = emails[i]
|
email = emails[i]
|
||||||
exp = re.compile(re.escape(email).join(regexp.split('<>')), re.MULTILINE)
|
exp = re.compile(re.escape(email).join(regexp.split('<>')), re.MULTILINE)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue