Skip to content

bpo-46565: del loop vars that are leaking into module namespaces #30993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Lib/_compat_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,4 @@

for excname in PYTHON3_IMPORTERROR_EXCEPTIONS:
REVERSE_NAME_MAPPING[('builtins', excname)] = ('exceptions', 'ImportError')
del excname
3 changes: 3 additions & 0 deletions Lib/email/contentmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions Lib/email/quoprimime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions Lib/http/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
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
Expand Down
1 change: 1 addition & 0 deletions Lib/json/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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')

Expand Down
1 change: 1 addition & 0 deletions Lib/lib2to3/pgen2/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,4 @@ def report(self):
if line:
op, name = line.split()
opmap[op] = getattr(token, name)
del line, op, name
1 change: 1 addition & 0 deletions Lib/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ def getpreferredencoding(do_setlocale=True):
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
Expand Down
10 changes: 5 additions & 5 deletions Lib/multiprocessing/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Lib/multiprocessing/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ def close(self):
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()
1 change: 1 addition & 0 deletions Lib/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def is_python_build(check_home=False):
scheme['headers'] = scheme['include']
scheme['include'] = '{srcdir}/Include'
scheme['platinclude'] = '{projectbase}/.'
del scheme


def _subst_vars(s, local_vars):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def istest(self, predicate, exp):
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"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha! this test should have caught the issue earlier 🙂

support.check__all__(self, inspect, not_exported=("modulesbyfile",))

def generator_function_example(self):
for i in range(2):
Expand Down
2 changes: 2 additions & 0 deletions Lib/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def _compile(expr):
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.
Expand All @@ -153,6 +154,7 @@ def _compile(expr):
single_quoted.add(u)
for u in (t + '"""', t + "'''"):
triple_quoted.add(u)
del t, u

tabsize = 8

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove loop variables that are leaking into modules' namespaces.