Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replaced type(NotImplemented) and type(None)
`type(NotImplemented)` and `type(None)` have, respectively, been replaced with `types.NotImplementedType` and `types.NoneType`
  • Loading branch information
Bas van Beek committed Sep 21, 2020
commit 2791a239bacfe1f16e9672ca063cdb1f29e9a147
4 changes: 2 additions & 2 deletions Lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def __new__(cls, *args, **kwargs):
Num: (int, float, complex),
Str: (str,),
Bytes: (bytes,),
NameConstant: (type(None), bool),
NameConstant: (types.NoneType, bool),
Ellipsis: (types.EllipsisType,),
}
_const_types_not = {
Expand All @@ -581,7 +581,7 @@ def __new__(cls, *args, **kwargs):

_const_node_type_names = {
bool: 'NameConstant', # should be before int
type(None): 'NameConstant',
types.NoneType: 'NameConstant',
int: 'Num',
float: 'Num',
complex: 'Num',
Expand Down
8 changes: 4 additions & 4 deletions Lib/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ def copy(x):

def _copy_immutable(x):
return x
for t in (type(None), int, float, bool, complex, str, tuple,
for t in (types.NoneType, int, float, bool, complex, str, tuple,
bytes, frozenset, type, range, slice, property,
types.BuiltinFunctionType, types.EllipsisType,
type(NotImplemented), types.FunctionType, weakref.ref):
types.NotImplementedType, types.FunctionType, weakref.ref):
d[t] = _copy_immutable
t = getattr(types, "CodeType", None)
if t is not None:
Expand Down Expand Up @@ -181,9 +181,9 @@ def deepcopy(x, memo=None, _nil=[]):

def _deepcopy_atomic(x, memo):
return x
d[type(None)] = _deepcopy_atomic
d[types.NoneType] = _deepcopy_atomic
d[types.EllipsisType] = _deepcopy_atomic
d[type(NotImplemented)] = _deepcopy_atomic
d[types.NotImplementedType] = _deepcopy_atomic
d[int] = _deepcopy_atomic
d[float] = _deepcopy_atomic
d[bool] = _deepcopy_atomic
Expand Down
4 changes: 2 additions & 2 deletions Lib/distutils/unixccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* link shared library handled by 'cc -shared'
"""

import os, sys, re
import os, sys, re, types

from distutils import sysconfig
from distutils.dep_util import newer
Expand Down Expand Up @@ -157,7 +157,7 @@ def link(self, target_desc, objects,

lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
libraries)
if not isinstance(output_dir, (str, type(None))):
if not isinstance(output_dir, (str, types.NoneType)):
raise TypeError("'output_dir' must be a string or None")
if output_dir is not None:
output_filename = os.path.join(output_dir, output_filename)
Expand Down
3 changes: 2 additions & 1 deletion Lib/idlelib/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import _thread as thread
import threading
import warnings
import types

from idlelib import autocomplete # AutoComplete, fetch_encodings
from idlelib import calltip # Calltip
Expand Down Expand Up @@ -558,7 +559,7 @@ def runcode(self, code):
except SystemExit as e:
if e.args: # SystemExit called with an argument.
ob = e.args[0]
if not isinstance(ob, (type(None), int)):
if not isinstance(ob, (types.NoneType, int)):
print('SystemExit: ' + str(ob), file=sys.stderr)
# Return to the interactive prompt.
except:
Expand Down
2 changes: 1 addition & 1 deletion Lib/imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def find_module(name, path=None):
"""
if not isinstance(name, str):
raise TypeError("'name' must be a str, not {}".format(type(name)))
elif not isinstance(path, (type(None), list)):
elif not isinstance(path, (types.NoneType, list)):
# Backwards-compatibility
raise RuntimeError("'path' must be None or a list, "
"not {}".format(type(path)))
Expand Down
2 changes: 1 addition & 1 deletion Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ def wrap_value(s):
except NameError:
raise RuntimeError()

if isinstance(value, (str, int, float, bytes, bool, type(None))):
if isinstance(value, (str, int, float, bytes, bool, types.NoneType)):
return ast.Constant(value)
raise RuntimeError()

Expand Down
2 changes: 0 additions & 2 deletions Lib/lib2to3/fixes/fix_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
'ListType': 'list',
'LongType': 'int',
'ObjectType' : 'object',
'NoneType': 'type(None)',
'NotImplementedType' : 'type(NotImplemented)',
'SliceType' : 'slice',
'StringType': 'bytes', # XXX ?
'StringTypes' : '(str,)', # XXX ?
Expand Down
4 changes: 0 additions & 4 deletions Lib/lib2to3/tests/test_fixers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3276,10 +3276,6 @@ def test_basic_types_convert(self):
a = """int"""
self.check(b, a)

b = """types.NoneType"""
a = """type(None)"""
self.check(b, a)

b = "types.StringTypes"
a = "(str,)"
self.check(b, a)
Expand Down
12 changes: 6 additions & 6 deletions Lib/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

"""

from types import FunctionType, EllipsisType
import types
from copyreg import dispatch_table
from copyreg import _extension_registry, _inverted_registry, _extension_cache
from itertools import islice
Expand Down Expand Up @@ -737,7 +737,7 @@ def save_reduce(self, func, args, state=None, listitems=None,

def save_none(self, obj):
self.write(NONE)
dispatch[type(None)] = save_none
dispatch[types.NoneType] = save_none

def save_bool(self, obj):
if self.proto >= 2:
Expand Down Expand Up @@ -1117,15 +1117,15 @@ def save_global(self, obj, name=None):
self.memoize(obj)

def save_type(self, obj):
if obj is type(None):
if obj is types.NoneType:
return self.save_reduce(type, (None,), obj=obj)
elif obj is type(NotImplemented):
elif obj is types.NotImplementedType:
return self.save_reduce(type, (NotImplemented,), obj=obj)
elif obj is EllipsisType:
elif obj is types.EllipsisType:
return self.save_reduce(type, (...,), obj=obj)
return self.save_global(obj)

dispatch[FunctionType] = save_global
dispatch[types.FunctionType] = save_global
dispatch[type] = save_type


Expand Down
3 changes: 2 additions & 1 deletion Lib/pickletools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pickle
import re
import sys
import types

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

Expand Down Expand Up @@ -1017,7 +1018,7 @@ def __repr__(self):

pynone = StackObject(
name="None",
obtype=type(None),
obtype=types.NoneType,
doc="The Python None object.")

pytuple = StackObject(
Expand Down
2 changes: 1 addition & 1 deletion Lib/pprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def _safe_repr(object, context, maxlevels, level, sort_dicts):
return rep, (rep and not rep.startswith('<')), False

_builtin_scalars = frozenset({str, bytes, bytearray, int, float, complex,
bool, type(None)})
bool, _types.NoneType})

def _recursion(object):
return ("<Recursion on %s with id=%s>"
Expand Down
2 changes: 1 addition & 1 deletion Lib/pydoc_data/topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@
'explicitly return a\n'
'value. It supports no special operations. There is '
'exactly one null\n'
'object, named "None" (a built-in name). "type(None)()" '
'object, named "None" (a built-in name). "types.NoneType()" '
'produces the\n'
'same singleton.\n'
'\n'
Expand Down
3 changes: 2 additions & 1 deletion Lib/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from bisect import bisect as _bisect
import os as _os
import _random
import types

try:
# hashlib is pretty heavy to load, try lean internal module first
Expand Down Expand Up @@ -154,7 +155,7 @@ def seed(self, a=None, version=2):
a += _sha512(a).digest()
a = int.from_bytes(a, 'big')

elif not isinstance(a, (type(None), int, float, str, bytes, bytearray)):
elif not isinstance(a, (types.NoneType, int, float, str, bytes, bytearray)):
_warn('Seeding based on hashing is deprecated\n'
'since Python 3.9 and will be removed in a subsequent '
'version. The only \n'
Expand Down
2 changes: 1 addition & 1 deletion Lib/runpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def run_path(path_name, init_globals=None, run_name=None):
if type(importer).__module__ == 'imp':
if type(importer).__name__ == 'NullImporter':
is_NullImporter = True
if isinstance(importer, type(None)) or is_NullImporter:
if isinstance(importer, types.NoneType) or is_NullImporter:
# Not a valid sys.path entry, so run the code directly
# execfile() doesn't help as we want to allow compiled files
code, fname = _get_code_from_file(run_name, path_name)
Expand Down
9 changes: 5 additions & 4 deletions Lib/sqlite3/test/userfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.

import types
import unittest
import unittest.mock
import sqlite3 as sqlite
Expand Down Expand Up @@ -49,7 +50,7 @@ def func_isint(v):
def func_isfloat(v):
return type(v) is float
def func_isnone(v):
return type(v) is type(None)
return type(v) is types.NoneType
def func_isblob(v):
return isinstance(v, (bytes, memoryview))
def func_islonglong(v):
Expand Down Expand Up @@ -107,7 +108,7 @@ def __init__(self):
self.val = None

def step(self, whichType, val):
theType = {"str": str, "int": int, "float": float, "None": type(None),
theType = {"str": str, "int": int, "float": float, "None": types.NoneType,
"blob": bytes}
self.val = int(theType[whichType] is type(val))

Expand All @@ -119,7 +120,7 @@ def __init__(self):
self.val = 0

def step(self, whichType, *vals):
theType = {"str": str, "int": int, "float": float, "None": type(None),
theType = {"str": str, "int": int, "float": float, "None": types.NoneType,
"blob": bytes}
for val in vals:
self.val += int(theType[whichType] is type(val))
Expand Down Expand Up @@ -211,7 +212,7 @@ def CheckFuncReturnNull(self):
cur = self.con.cursor()
cur.execute("select returnnull()")
val = cur.fetchone()[0]
self.assertEqual(type(val), type(None))
self.assertEqual(type(val), types.NoneType)
self.assertEqual(val, None)

def CheckFuncReturnBlob(self):
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import inspect
import builtins
import unittest
import types
from unittest.mock import Mock
from typing import ClassVar, Any, List, Union, Tuple, Dict, Generic, TypeVar, Optional
from typing import get_type_hints
Expand Down Expand Up @@ -2026,7 +2027,7 @@ class C:
def test_docstring_one_field_with_default_none(self):
@dataclass
class C:
x: Union[int, type(None)] = None
x: Union[int, types.NoneType] = None

self.assertDocStrEqual(C.__doc__, "C(x:Optional[int]=None)")

Expand Down Expand Up @@ -2955,7 +2956,7 @@ def test_text_annotations(self):
self.assertEqual(
get_type_hints(dataclass_textanno.Bar.__init__),
{'foo': dataclass_textanno.Foo,
'return': type(None)})
'return': types.NoneType})


class TestMakeDataclass(unittest.TestCase):
Expand Down
22 changes: 11 additions & 11 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3260,7 +3260,7 @@ class Int(int): __slots__ = []
cant(2, bool)
o = object()
cant(o, type(1))
cant(o, type(None))
cant(o, types.NoneType)
del o
class G(object):
__slots__ = ["a", "b"]
Expand Down Expand Up @@ -4000,35 +4000,35 @@ class D(C):

def test_unsubclassable_types(self):
with self.assertRaises(TypeError):
class X(type(None)):
class X(types.NoneType):
pass
with self.assertRaises(TypeError):
class X(object, type(None)):
class X(object, types.NoneType):
pass
with self.assertRaises(TypeError):
class X(type(None), object):
class X(types.NoneType, object):
pass
class O(object):
pass
with self.assertRaises(TypeError):
class X(O, type(None)):
class X(O, types.NoneType):
pass
with self.assertRaises(TypeError):
class X(type(None), O):
class X(types.NoneType, O):
pass

class X(object):
pass
with self.assertRaises(TypeError):
X.__bases__ = type(None),
X.__bases__ = types.NoneType,
with self.assertRaises(TypeError):
X.__bases__ = object, type(None)
X.__bases__ = object, types.NoneType
with self.assertRaises(TypeError):
X.__bases__ = type(None), object
X.__bases__ = types.NoneType, object
with self.assertRaises(TypeError):
X.__bases__ = O, type(None)
X.__bases__ = O, types.NoneType
with self.assertRaises(TypeError):
X.__bases__ = type(None), O
X.__bases__ = types.NoneType, O

def test_mutable_bases_with_failing_mro(self):
# Testing mutable bases with failing mro...
Expand Down
9 changes: 5 additions & 4 deletions Lib/test/test_getargs2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import math
import string
import sys
import types
from test import support
from test.support import import_helper
# Skip this test if the _testcapi module isn't available.
Expand Down Expand Up @@ -567,11 +568,11 @@ def test_args(self):

ret = get_args()
self.assertIn(ret, ((), None))
self.assertIn(type(ret), (tuple, type(None)))
self.assertIn(type(ret), (tuple, types.NoneType))

ret = get_args(*())
self.assertIn(ret, ((), None))
self.assertIn(type(ret), (tuple, type(None)))
self.assertIn(type(ret), (tuple, types.NoneType))

def test_tuple(self):
from _testcapi import getargs_tuple
Expand Down Expand Up @@ -605,11 +606,11 @@ def test_kwargs(self):

ret = get_kwargs()
self.assertIn(ret, ({}, None))
self.assertIn(type(ret), (dict, type(None)))
self.assertIn(type(ret), (dict, types.NoneType))

ret = get_kwargs(**{})
self.assertIn(ret, ({}, None))
self.assertIn(type(ret), (dict, type(None)))
self.assertIn(type(ret), (dict, types.NoneType))

def test_positional_args(self):
# using all positional args
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_nntplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os.path
import re
import threading
import types

from test import support
from test.support import socket_helper
Expand Down Expand Up @@ -126,7 +127,7 @@ def _check_art_dict(self, art_dict):
"references", ":bytes", ":lines"}
)
for v in art_dict.values():
self.assertIsInstance(v, (str, type(None)))
self.assertIsInstance(v, (str, types.NoneType))

def test_xover(self):
resp, count, first, last, name = self.server.group(self.GROUP_NAME)
Expand Down
Loading