Kaydet (Commit) f3042782 authored tarafından Brett Cannon's avatar Brett Cannon

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.
üst eeb114b0
...@@ -24,6 +24,7 @@ __author__ = 'Ka-Ping Yee <ping@lfw.org>' ...@@ -24,6 +24,7 @@ __author__ = 'Ka-Ping Yee <ping@lfw.org>'
__credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, ' __credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, '
'Skip Montanaro, Raymond Hettinger, Trent Nelson, ' 'Skip Montanaro, Raymond Hettinger, Trent Nelson, '
'Michael Foord') 'Michael Foord')
import builtins
import re import re
import sys import sys
from token import * from token import *
...@@ -335,13 +336,11 @@ def detect_encoding(readline): ...@@ -335,13 +336,11 @@ def detect_encoding(readline):
return default, [first, second] return default, [first, second]
_builtin_open = open
def open(filename): def open(filename):
"""Open a file in read only mode using the encoding detected by """Open a file in read only mode using the encoding detected by
detect_encoding(). detect_encoding().
""" """
buffer = _builtin_open(filename, 'rb') buffer = builtins.open(filename, 'rb')
encoding, lines = detect_encoding(buffer.readline) encoding, lines = detect_encoding(buffer.readline)
buffer.seek(0) buffer.seek(0)
text = TextIOWrapper(buffer, encoding, line_buffering=True) text = TextIOWrapper(buffer, encoding, line_buffering=True)
......
...@@ -27,6 +27,8 @@ Core and Builtins ...@@ -27,6 +27,8 @@ Core and Builtins
Library Library
------- -------
- Issue #11074: Make 'tokenize' so it can be reloaded.
- Issue #11085: Moved collections abstract base classes into a separate - Issue #11085: Moved collections abstract base classes into a separate
module called collections.abc, following the pattern used by importlib.abc. module called collections.abc, following the pattern used by importlib.abc.
For backwards compatibility, the names are imported into the collections For backwards compatibility, the names are imported into the collections
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment