Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f304278

Browse files
committed
Issue #11074: Make 'tokenize' so it can be reloaded.
The module stored away the 'open' object as found in the global namespace (which fell through to the built-in namespace) since it defined its own 'open'. Problem is that if you reloaded the module it then grabbed the 'open' defined in the previous load, leading to code that infinite recursed. Switched to simply call builtins.open directly.
1 parent eeb114b commit f304278

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

Lib/tokenize.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
__credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, '
2525
'Skip Montanaro, Raymond Hettinger, Trent Nelson, '
2626
'Michael Foord')
27+
import builtins
2728
import re
2829
import sys
2930
from token import *
@@ -335,13 +336,11 @@ def find_cookie(line):
335336
return default, [first, second]
336337

337338

338-
_builtin_open = open
339-
340339
def open(filename):
341340
"""Open a file in read only mode using the encoding detected by
342341
detect_encoding().
343342
"""
344-
buffer = _builtin_open(filename, 'rb')
343+
buffer = builtins.open(filename, 'rb')
345344
encoding, lines = detect_encoding(buffer.readline)
346345
buffer.seek(0)
347346
text = TextIOWrapper(buffer, encoding, line_buffering=True)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Core and Builtins
2727
Library
2828
-------
2929

30+
- Issue #11074: Make 'tokenize' so it can be reloaded.
31+
3032
- Issue #11085: Moved collections abstract base classes into a separate
3133
module called collections.abc, following the pattern used by importlib.abc.
3234
For backwards compatibility, the names are imported into the collections

0 commit comments

Comments
 (0)