diff --git a/Lib/bz2.py b/Lib/bz2.py index 6f47bfaf6c..6c5a60d619 100644 --- a/Lib/bz2.py +++ b/Lib/bz2.py @@ -9,6 +9,7 @@ __all__ = ["BZ2File", "BZ2Compressor", "BZ2Decompressor", __author__ = "Nadeem Vawda " +from builtins import open as _builtin_open import io import warnings @@ -27,8 +28,6 @@ _MODE_WRITE = 3 _BUFFER_SIZE = 8192 -_builtin_open = open - class BZ2File(io.BufferedIOBase): diff --git a/Lib/tarfile.py b/Lib/tarfile.py index ea7a89a8d3..720bbf7d13 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -38,6 +38,7 @@ __credits__ = "Gustavo Niemeyer, Niels Gust\u00e4bel, Richard Townsend." #--------- # Imports #--------- +from builtins import open as bltn_open import sys import os import io @@ -2433,7 +2434,6 @@ def is_tarfile(name): except TarError: return False -bltn_open = open open = TarFile.open diff --git a/Lib/tokenize.py b/Lib/tokenize.py index 0659c55a06..8bc83fda54 100644 --- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -24,6 +24,7 @@ __author__ = 'Ka-Ping Yee ' __credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, ' 'Skip Montanaro, Raymond Hettinger, Trent Nelson, ' 'Michael Foord') +from builtins import open as _builtin_open from codecs import lookup, BOM_UTF8 import collections from io import TextIOWrapper @@ -429,8 +430,6 @@ def detect_encoding(readline): return default, [first, second] -_builtin_open = open - def open(filename): """Open a file in read only mode using the encoding detected by detect_encoding(). diff --git a/Misc/NEWS b/Misc/NEWS index d6b2583f45..6b116b325a 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,9 @@ Core and Builtins Library ------- +- Issue #23615: Modules bz2, tarfile and tokenize now can be reloaded with + imp.reload(). Patch by Thomas Kluyver. + - Issue #23605: os.walk() now calls os.scandir() instead of os.listdir(). The usage of os.scandir() reduces the number of calls to os.stat(). Initial patch written by Ben Hoyt. diff --git a/Tools/freeze/bkfile.py b/Tools/freeze/bkfile.py index 58246fa2ad..6abacc9e0e 100644 --- a/Tools/freeze/bkfile.py +++ b/Tools/freeze/bkfile.py @@ -1,4 +1,4 @@ -_orig_open = open +from builtins import open as _orig_open class _BkFile: def __init__(self, file, mode, bufsize):