Skip to content

Commit 84ebe18

Browse files
author
Bas van Beek
committed
Revert the type(...) to types.... replacements
Reverts 2791a23 and 0a97a88. Save this for a follow up.
1 parent 33caa6f commit 84ebe18

28 files changed

+72
-78
lines changed

Lib/ast.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
:copyright: Copyright 2008 by Armin Ronacher.
2525
:license: Python License.
2626
"""
27-
import types
2827
import sys
2928
from _ast import *
3029
from contextlib import contextmanager, nullcontext
@@ -572,22 +571,22 @@ def __new__(cls, *args, **kwargs):
572571
Num: (int, float, complex),
573572
Str: (str,),
574573
Bytes: (bytes,),
575-
NameConstant: (types.NoneType, bool),
576-
Ellipsis: (types.EllipsisType,),
574+
NameConstant: (type(None), bool),
575+
Ellipsis: (type(...),),
577576
}
578577
_const_types_not = {
579578
Num: (bool,),
580579
}
581580

582581
_const_node_type_names = {
583582
bool: 'NameConstant', # should be before int
584-
types.NoneType: 'NameConstant',
583+
type(None): 'NameConstant',
585584
int: 'Num',
586585
float: 'Num',
587586
complex: 'Num',
588587
str: 'Str',
589588
bytes: 'Bytes',
590-
types.EllipsisType: 'Ellipsis',
589+
type(...): 'Ellipsis',
591590
}
592591

593592
class slice(AST):

Lib/copy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ def copy(x):
106106

107107
def _copy_immutable(x):
108108
return x
109-
for t in (types.NoneType, int, float, bool, complex, str, tuple,
109+
for t in (type(None), int, float, bool, complex, str, tuple,
110110
bytes, frozenset, type, range, slice, property,
111-
types.BuiltinFunctionType, types.EllipsisType,
112-
types.NotImplementedType, types.FunctionType, weakref.ref):
111+
types.BuiltinFunctionType, type(Ellipsis), type(NotImplemented),
112+
types.FunctionType, weakref.ref):
113113
d[t] = _copy_immutable
114114
t = getattr(types, "CodeType", None)
115115
if t is not None:
@@ -181,9 +181,9 @@ def deepcopy(x, memo=None, _nil=[]):
181181

182182
def _deepcopy_atomic(x, memo):
183183
return x
184-
d[types.NoneType] = _deepcopy_atomic
185-
d[types.EllipsisType] = _deepcopy_atomic
186-
d[types.NotImplementedType] = _deepcopy_atomic
184+
d[type(None)] = _deepcopy_atomic
185+
d[type(Ellipsis)] = _deepcopy_atomic
186+
d[type(NotImplemented)] = _deepcopy_atomic
187187
d[int] = _deepcopy_atomic
188188
d[float] = _deepcopy_atomic
189189
d[bool] = _deepcopy_atomic

Lib/distutils/unixccompiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* link shared library handled by 'cc -shared'
1414
"""
1515

16-
import os, sys, re, types
16+
import os, sys, re
1717

1818
from distutils import sysconfig
1919
from distutils.dep_util import newer
@@ -157,7 +157,7 @@ def link(self, target_desc, objects,
157157

158158
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
159159
libraries)
160-
if not isinstance(output_dir, (str, types.NoneType)):
160+
if not isinstance(output_dir, (str, type(None))):
161161
raise TypeError("'output_dir' must be a string or None")
162162
if output_dir is not None:
163163
output_filename = os.path.join(output_dir, output_filename)

Lib/idlelib/run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import _thread as thread
1616
import threading
1717
import warnings
18-
import types
1918

2019
from idlelib import autocomplete # AutoComplete, fetch_encodings
2120
from idlelib import calltip # Calltip
@@ -559,7 +558,7 @@ def runcode(self, code):
559558
except SystemExit as e:
560559
if e.args: # SystemExit called with an argument.
561560
ob = e.args[0]
562-
if not isinstance(ob, (types.NoneType, int)):
561+
if not isinstance(ob, (type(None), int)):
563562
print('SystemExit: ' + str(ob), file=sys.stderr)
564563
# Return to the interactive prompt.
565564
except:

Lib/imp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def find_module(name, path=None):
264264
"""
265265
if not isinstance(name, str):
266266
raise TypeError("'name' must be a str, not {}".format(type(name)))
267-
elif not isinstance(path, (types.NoneType, list)):
267+
elif not isinstance(path, (type(None), list)):
268268
# Backwards-compatibility
269269
raise RuntimeError("'path' must be None or a list, "
270270
"not {}".format(type(path)))

Lib/inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ def wrap_value(s):
20342034
except NameError:
20352035
raise RuntimeError()
20362036

2037-
if isinstance(value, (str, int, float, bytes, bool, types.NoneType)):
2037+
if isinstance(value, (str, int, float, bytes, bool, type(None))):
20382038
return ast.Constant(value)
20392039
raise RuntimeError()
20402040

Lib/lib2to3/fixes/fix_types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@
3030
'ComplexType' : 'complex',
3131
'DictType': 'dict',
3232
'DictionaryType' : 'dict',
33+
'EllipsisType' : 'type(Ellipsis)',
3334
#'FileType' : 'io.IOBase',
3435
'FloatType': 'float',
3536
'IntType': 'int',
3637
'ListType': 'list',
3738
'LongType': 'int',
3839
'ObjectType' : 'object',
40+
'NoneType': 'type(None)',
41+
'NotImplementedType' : 'type(NotImplemented)',
3942
'SliceType' : 'slice',
4043
'StringType': 'bytes', # XXX ?
4144
'StringTypes' : '(str,)', # XXX ?

Lib/lib2to3/tests/test_fixers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,6 +3276,10 @@ def test_basic_types_convert(self):
32763276
a = """int"""
32773277
self.check(b, a)
32783278

3279+
b = """types.NoneType"""
3280+
a = """type(None)"""
3281+
self.check(b, a)
3282+
32793283
b = "types.StringTypes"
32803284
a = "(str,)"
32813285
self.check(b, a)

Lib/pickle.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
2424
"""
2525

26-
import types
26+
from types import FunctionType
2727
from copyreg import dispatch_table
2828
from copyreg import _extension_registry, _inverted_registry, _extension_cache
2929
from itertools import islice
@@ -737,7 +737,7 @@ def save_reduce(self, func, args, state=None, listitems=None,
737737

738738
def save_none(self, obj):
739739
self.write(NONE)
740-
dispatch[types.NoneType] = save_none
740+
dispatch[type(None)] = save_none
741741

742742
def save_bool(self, obj):
743743
if self.proto >= 2:
@@ -1117,15 +1117,15 @@ def save_global(self, obj, name=None):
11171117
self.memoize(obj)
11181118

11191119
def save_type(self, obj):
1120-
if obj is types.NoneType:
1120+
if obj is type(None):
11211121
return self.save_reduce(type, (None,), obj=obj)
1122-
elif obj is types.NotImplementedType:
1122+
elif obj is type(NotImplemented):
11231123
return self.save_reduce(type, (NotImplemented,), obj=obj)
1124-
elif obj is types.EllipsisType:
1124+
elif obj is type(...):
11251125
return self.save_reduce(type, (...,), obj=obj)
11261126
return self.save_global(obj)
11271127

1128-
dispatch[types.FunctionType] = save_global
1128+
dispatch[FunctionType] = save_global
11291129
dispatch[type] = save_type
11301130

11311131

Lib/pickletools.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import pickle
1616
import re
1717
import sys
18-
import types
1918

2019
__all__ = ['dis', 'genops', 'optimize']
2120

@@ -1018,7 +1017,7 @@ def __repr__(self):
10181017

10191018
pynone = StackObject(
10201019
name="None",
1021-
obtype=types.NoneType,
1020+
obtype=type(None),
10221021
doc="The Python None object.")
10231022

10241023
pytuple = StackObject(

0 commit comments

Comments
 (0)