PythonCharmers / python-future

Easy, clean, reliable Python 2/3 compatibility
http://python-future.org
MIT License
1.17k stars 292 forks source link

`hooks` breaks `from x import *` (0.15.2, Python 2) #238

Open itamarst opened 7 years ago

itamarst commented 7 years ago
from future.standard_library import hooks

with hooks():
    from urllib.parse import urlparse, urlencode
    from urllib.request import urlopen, Request
    from urllib.error import HTTPError

This code made from mymodule import * fail. That is, it runs, but nothing gets imported into the module running that, as if mymodule is empty. Later calls to from mymodule import *, e.g. in a debuger, do work. My guess is the issue is something to do with copying and then re-inserting stuff from sys.modules that the install_hooks-related code does; probably modules are being copied at the wrong time, when they're still half-empty or something.

itamarst commented 7 years ago

Unfortunately the real code is complex and I'm having trouble creating a reproducer, but updated my description above with plausible theory.

edschofield commented 7 years ago

Thanks for the feedback. I have seen this before too during development of some modules in future.backports, but it was hard to reproduce for me too. I ended up removing the use of hooks. It may be time to mark the hooks interface as deprecated.

Meanwhile, please let us know if you succeed in reproducing it reliably.