[Python-Dev] If you shadow a module in the standard library that IDLE depends on, bad things happen
Nathaniel Smith
njs at pobox.com
Thu Oct 29 13:30:42 EDT 2015
More information about the Python-Dev mailing list
Thu Oct 29 13:30:42 EDT 2015
- Previous message (by thread): [Python-Dev] If you shadow a module in the standard library that IDLE depends on, bad things happen
- Next message (by thread): [Python-Dev] If you shadow a module in the standard library that IDLE depends on, bad things happen
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Oct 29, 2015 10:22 AM, "Brett Cannon" <brett at python.org> wrote: > > > > On Thu, 29 Oct 2015 at 09:00 Laura Creighton <lac at openend.se> wrote: >> >> >> see the following: >> lac at smartwheels:~/junk$ echo "print ('hello there')" >string.py >> lac at smartwheels:~/junk$ idle-python3.5 >> hello there >> Traceback (most recent call last): >> File "<string>", line 1, in <module> >> File "/usr/lib/python3.5/idlelib/run.py", line 10, in <module> >> from idlelib import CallTips >> File "/usr/lib/python3.5/idlelib/CallTips.py", line 16, in <module> >> from idlelib.HyperParser import HyperParser >> File "/usr/lib/python3.5/idlelib/HyperParser.py", line 14, in <module> >> _ASCII_ID_CHARS = frozenset(string.ascii_letters + string.digits + "_") >> AttributeError: module 'string' has no attribute 'ascii_letters' >> >> IDLE then produces a popup that says: >> >> IDLE's subprocess didn't make connection. Either IDLE can't stat a subprocess por personal firewall software is blocking the connection. <ok> >> >> -------- >> >> I think that life would be a whole lot easier for people if instead we got >> a message: >> >> Warning: local file /u/lac/junk/string.py shadows module named string in the >> Standard Library >> >> I think that it is python exec that would have to do this -- though of >> course the popup could also warn about shadowing in general, instead of >> sending people on wild goose chases over their firewalls. >> >> Would this be hard to do? > > > It would require a custom importer or overriding __import__ but it's doable. Is there any reason not to issue such warnings by default in the standard importer? The issue of accidentally shadowing stdlib modules isn't restricted to idle, it's difficult for idle to handle correctly (how do you define a custom importer if you don't yet have access to the stdlib?), and it's not like there's any legitimate reason to want string.py in the working directory to auto-monkeypatch stdlib string. (I know saying that last part out loud will probably just cause someone to pop out of the woodwork and explain how shadowing the sys module is a great idea and they do it all the time or whatever, but I guess I'll take that risk :-).) -n -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20151029/e9fafd4f/attachment.html>
- Previous message (by thread): [Python-Dev] If you shadow a module in the standard library that IDLE depends on, bad things happen
- Next message (by thread): [Python-Dev] If you shadow a module in the standard library that IDLE depends on, bad things happen
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list