[Python-checkins] gh-99325: Remove unused `NameError` handling (#99326)

AlexWaygood webhook-mailer at python.org
Fri Nov 11 04:57:03 EST 2022


https://github.com/python/cpython/commit/faf7dfa656bd52959156fed39a4c680b2b13e032
commit: faf7dfa656bd52959156fed39a4c680b2b13e032
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: AlexWaygood <Alex.Waygood at Gmail.com>
date: 2022-11-11T09:56:57Z
summary:

gh-99325: Remove unused `NameError` handling (#99326)

files:
M Lib/copyreg.py
M Lib/tarfile.py

diff --git a/Lib/copyreg.py b/Lib/copyreg.py
index c8a52a2dc63a..578392409b40 100644
--- a/Lib/copyreg.py
+++ b/Lib/copyreg.py
@@ -25,16 +25,10 @@ def constructor(object):
 
 # Example: provide pickling support for complex numbers.
 
-try:
-    complex
-except NameError:
-    pass
-else:
+def pickle_complex(c):
+    return complex, (c.real, c.imag)
 
-    def pickle_complex(c):
-        return complex, (c.real, c.imag)
-
-    pickle(complex, pickle_complex, complex)
+pickle(complex, pickle_complex, complex)
 
 def pickle_union(obj):
     import functools, operator
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index a08f247f496b..42100e9a3943 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -57,13 +57,9 @@
     grp = None
 
 # os.symlink on Windows prior to 6.0 raises NotImplementedError
-symlink_exception = (AttributeError, NotImplementedError)
-try:
-    # OSError (winerror=1314) will be raised if the caller does not hold the
-    # SeCreateSymbolicLinkPrivilege privilege
-    symlink_exception += (OSError,)
-except NameError:
-    pass
+# OSError (winerror=1314) will be raised if the caller does not hold the
+# SeCreateSymbolicLinkPrivilege privilege
+symlink_exception = (AttributeError, NotImplementedError, OSError)
 
 # from tarfile import *
 __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError", "ReadError",



More information about the Python-checkins mailing list