]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46565: `del` loop vars that are leaking into module namespaces (GH-30993)
authorNikita Sobolev <mail@sobolevn.me>
Thu, 3 Feb 2022 09:20:08 +0000 (12:20 +0300)
committerGitHub <noreply@github.com>
Thu, 3 Feb 2022 09:20:08 +0000 (11:20 +0200)
14 files changed:
Lib/_compat_pickle.py
Lib/email/contentmanager.py
Lib/email/quoprimime.py
Lib/http/cookiejar.py
Lib/inspect.py
Lib/json/encoder.py
Lib/lib2to3/pgen2/grammar.py
Lib/locale.py
Lib/multiprocessing/managers.py
Lib/multiprocessing/process.py
Lib/sysconfig.py
Lib/test/test_inspect.py
Lib/tokenize.py
Misc/NEWS.d/next/Library/2022-01-28-19-48-31.bpo-46565.bpZXO4.rst [new file with mode: 0644]

index f68496ae639f5f880ae5f4ca0a220a29d2e354be..65a94b6b1bdfd53b48d5abe1d33f21402af0289e 100644 (file)
@@ -249,3 +249,4 @@ PYTHON3_IMPORTERROR_EXCEPTIONS = (
 
 for excname in PYTHON3_IMPORTERROR_EXCEPTIONS:
     REVERSE_NAME_MAPPING[('builtins', excname)] = ('exceptions', 'ImportError')
+del excname
index fcf278dbccbac9581e4de5cad5e2de252a2e4d4a..b4f5830beada4a2bb7353a4d6672d2397a7fb499 100644 (file)
@@ -72,12 +72,14 @@ def get_non_text_content(msg):
     return msg.get_payload(decode=True)
 for maintype in 'audio image video application'.split():
     raw_data_manager.add_get_handler(maintype, get_non_text_content)
+del maintype
 
 
 def get_message_content(msg):
     return msg.get_payload(0)
 for subtype in 'rfc822 external-body'.split():
     raw_data_manager.add_get_handler('message/'+subtype, get_message_content)
+del subtype
 
 
 def get_and_fixup_unknown_message_content(msg):
@@ -246,3 +248,4 @@ def set_bytes_content(msg, data, maintype, subtype, cte='base64',
     _finalize_set(msg, disposition, filename, cid, params)
 for typ in (bytes, bytearray, memoryview):
     raw_data_manager.add_set_handler(typ, set_bytes_content)
+del typ
index 94534f7ee1e33e626ffb71983cf24cd81c9f9854..27fcbb5a26e3ae2e3eca587ba47270b13dc0ca13 100644 (file)
@@ -148,6 +148,7 @@ def header_encode(header_bytes, charset='iso-8859-1'):
 _QUOPRI_BODY_ENCODE_MAP = _QUOPRI_BODY_MAP[:]
 for c in b'\r\n':
     _QUOPRI_BODY_ENCODE_MAP[c] = chr(c)
+del c
 
 def body_encode(body, maxlinelen=76, eol=NL):
     """Encode with quoted-printable, wrapping at maxlinelen characters.
index eaa76c26b9c591a6a5f5ea64cd5348e430bd7fad..ee433c0f78f4a4fe9a01a294d72b7ccf50c1407b 100644 (file)
@@ -89,8 +89,7 @@ def _timegm(tt):
 DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
 MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
           "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
-MONTHS_LOWER = []
-for month in MONTHS: MONTHS_LOWER.append(month.lower())
+MONTHS_LOWER = [month.lower() for month in MONTHS]
 
 def time2isoz(t=None):
     """Return a string representing time in seconds since epoch, t.
index d47f5b717471ce5646bbd00937c76e809a2ff240..eb45f81aa2d959f104c33d7f233f9c45a740d085 100644 (file)
@@ -156,6 +156,7 @@ from collections import namedtuple, OrderedDict
 mod_dict = globals()
 for k, v in dis.COMPILER_FLAG_NAMES.items():
     mod_dict["CO_" + v] = k
+del k, v, mod_dict
 
 # See Include/object.h
 TPFLAGS_IS_ABSTRACT = 1 << 20
index 21bff2c1a1fca33b336a73f8043375148beaf549..864f46d9dbb7266262395cb8dc70e007e2e617a5 100644 (file)
@@ -30,6 +30,7 @@ ESCAPE_DCT = {
 for i in range(0x20):
     ESCAPE_DCT.setdefault(chr(i), '\\u{0:04x}'.format(i))
     #ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i,))
+del i
 
 INFINITY = float('inf')
 
index 6a4d575ac2ccfce410e1d9076d99df8eb740e8d6..5d550aeb65e8dd10bb286267a7132ae380bbd038 100644 (file)
@@ -186,3 +186,4 @@ for line in opmap_raw.splitlines():
     if line:
         op, name = line.split()
         opmap[op] = getattr(token, name)
+del line, op, name
index 6d4f51929923f6f865dd774ddc5c7d601f540816..4bd31c9fa2cdf71b69103e489f29e822ddd3e862 100644 (file)
@@ -746,6 +746,7 @@ locale_encoding_alias = {
 for k, v in sorted(locale_encoding_alias.items()):
     k = k.replace('_', '')
     locale_encoding_alias.setdefault(k, v)
+del k, v
 
 #
 # The locale_alias table maps lowercase alias names to C locale names
index cf637c6cbbe8d145e1c5551796d99073360968d4..d97381926d47bcece939ec63469a5d7322702185 100644 (file)
@@ -49,11 +49,11 @@ def reduce_array(a):
 reduction.register(array.array, reduce_array)
 
 view_types = [type(getattr({}, name)()) for name in ('items','keys','values')]
-if view_types[0] is not list:       # only needed in Py3.0
-    def rebuild_as_list(obj):
-        return list, (list(obj),)
-    for view_type in view_types:
-        reduction.register(view_type, rebuild_as_list)
+def rebuild_as_list(obj):
+    return list, (list(obj),)
+for view_type in view_types:
+    reduction.register(view_type, rebuild_as_list)
+del view_type, view_types
 
 #
 # Type for identifying shared objects
index 0b2e0b45b2397be0a672b36b7e4c572b3996cf53..3917d2e4fa63ecaaa5eba444878544315c5d2bcc 100644 (file)
@@ -427,6 +427,7 @@ _exitcode_to_name = {}
 for name, signum in list(signal.__dict__.items()):
     if name[:3]=='SIG' and '_' not in name:
         _exitcode_to_name[-signum] = f'-{name}'
+del name, signum
 
 # For debug and leak testing
 _dangling = WeakSet()
index ef335c69421f5ea0d6b1358cb995d9173cd95060..d4a8a680286c1eaa34223b15f36536941b3dccf8 100644 (file)
@@ -192,6 +192,7 @@ if _PYTHON_BUILD:
         scheme['headers'] = scheme['include']
         scheme['include'] = '{srcdir}/Include'
         scheme['platinclude'] = '{projectbase}/.'
+    del scheme
 
 
 def _subst_vars(s, local_vars):
index 76fa6f7e2dab8495adafdcc40a342d2c8727254b..a553431bdccfb219892c921396e2bb690043fffb 100644 (file)
@@ -108,7 +108,7 @@ class IsTestBase(unittest.TestCase):
             self.assertFalse(other(obj), 'not %s(%s)' % (other.__name__, exp))
 
     def test__all__(self):
-        support.check__all__(self, inspect, not_exported=("k", "v", "mod_dict", "modulesbyfile"))
+        support.check__all__(self, inspect, not_exported=("modulesbyfile",))
 
 def generator_function_example(self):
     for i in range(2):
index 0b9e238310049cf0dfef3e17998d86c1d744d182..46d2224f5cc0833e4b38819d0255367bb3625ac4 100644 (file)
@@ -143,6 +143,7 @@ for _prefix in _all_string_prefixes():
     endpats[_prefix + '"'] = Double
     endpats[_prefix + "'''"] = Single3
     endpats[_prefix + '"""'] = Double3
+del _prefix
 
 # A set of all of the single and triple quoted string prefixes,
 #  including the opening quotes.
@@ -153,6 +154,7 @@ for t in _all_string_prefixes():
         single_quoted.add(u)
     for u in (t + '"""', t + "'''"):
         triple_quoted.add(u)
+del t, u
 
 tabsize = 8
 
diff --git a/Misc/NEWS.d/next/Library/2022-01-28-19-48-31.bpo-46565.bpZXO4.rst b/Misc/NEWS.d/next/Library/2022-01-28-19-48-31.bpo-46565.bpZXO4.rst
new file mode 100644 (file)
index 0000000..9b0969e
--- /dev/null
@@ -0,0 +1 @@
+Remove loop variables that are leaking into modules' namespaces.