[Python-checkins] gh-100815: Normalize `types` module usage in `copy` module (#100816)
AlexWaygood
webhook-mailer at python.org
Sat Jan 7 16:29:58 EST 2023
https://github.com/python/cpython/commit/951303fd855838d47765dcd05471e14311dc9fdd
commit: 951303fd855838d47765dcd05471e14311dc9fdd
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: AlexWaygood <Alex.Waygood at Gmail.com>
date: 2023-01-07T21:29:53Z
summary:
gh-100815: Normalize `types` module usage in `copy` module (#100816)
files:
M Lib/copy.py
diff --git a/Lib/copy.py b/Lib/copy.py
index 6e8c19bc652d..da2908ef623d 100644
--- a/Lib/copy.py
+++ b/Lib/copy.py
@@ -101,13 +101,11 @@ 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, type(Ellipsis), type(NotImplemented),
- types.FunctionType, weakref.ref):
- d[t] = _copy_immutable
-t = getattr(types, "CodeType", None)
-if t is not None:
+ types.BuiltinFunctionType, types.EllipsisType,
+ types.NotImplementedType, types.FunctionType, types.CodeType,
+ weakref.ref):
d[t] = _copy_immutable
d[list] = list.copy
@@ -173,9 +171,9 @@ def deepcopy(x, memo=None, _nil=[]):
def _deepcopy_atomic(x, memo):
return x
-d[type(None)] = _deepcopy_atomic
-d[type(Ellipsis)] = _deepcopy_atomic
-d[type(NotImplemented)] = _deepcopy_atomic
+d[types.NoneType] = _deepcopy_atomic
+d[types.EllipsisType] = _deepcopy_atomic
+d[types.NotImplementedType] = _deepcopy_atomic
d[int] = _deepcopy_atomic
d[float] = _deepcopy_atomic
d[bool] = _deepcopy_atomic
More information about the Python-checkins
mailing list