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
Reloading tokenize breaks tokenize.open() #67803
Comments
Issue bpo-22599 changed tokenize.open() from using builtins.open() to having a module-level reference to _builtin_open, stored by doing _builtin_open = open. However, on reloading the module, _builtin_open is pointed to tokenize.open from the last execution of the code, breaking tokenize.open(): >>> import tokenize
>>> tokenize.open
<function open at 0x7f15b660fc80>
>>> tokenize._builtin_open
<built-in function open>
>>> import imp; imp.reload(tokenize)
<module 'tokenize' from '/home/takluyver/miniconda3/envs/py34/lib/python3.4/tokenize.py'>
>>> tokenize.open
<function open at 0x7f15b660fbf8>
>>> tokenize._builtin_open
<function open at 0x7f15b660fc80>
>>> tokenize.open('foo.py')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/takluyver/miniconda3/envs/py34/lib/python3.4/tokenize.py", line 438, in open
buffer = _builtin_open(filename, 'rb')
TypeError: open() takes 1 positional argument but 2 were given The actual case where I'm seeing this error is nose logging a failure in a test suite, so it's not clear what is reloading tokenize, but it appears that something is. This just started failing when our Windows test system updated to Python 3.4.3. |
Patch attached to fix this. |
The same issue exists in Lib/bz2.py, Lib/tarfile.py, Tools/freeze/bkfile.py. May be write a code as from builtins import open as _builtin_open ? |
-B.patch as Serhiy suggests, for tokenize only for the time being. |
LGTM. Do you want to write a patch for other cases Thomas? |
Fixed the other three cases you pointed out (-B2.patch). |
LGTM. |
LGTM as well. You want to commit, Serhiy? If not assign to me and I will get to it on Friday. |
New changeset 383ba3699084 by Serhiy Storchaka in branch '3.4': New changeset 6e736a57a482 by Serhiy Storchaka in branch 'default': New changeset 36bd5add9732 by Serhiy Storchaka in branch '2.7': |
Is there a method to detect other reload bugs? |
Only grep. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: