Message253775
When users 'saveas', warn if name matches that of a stdlib modules. Note that shadowing is opposite for lib and binary (builtin) modules, so message needs to be different. I am not worrying about 3rd party modules on the search path (ie, site-packages), which would be shadowed like lib modules. Rough outline of code to add to IOBinding.
from os,path import dirname
import sys
# this part on initiallzation or first saveas call
def libmodules():
with open(dirname(dirname(__file__))) as lib:
for f in lib:
if <directory containing __init__.py#> or f.endswith(.py):
yield f
# test.test__all__ has this code
islibmodule = frozenset(libmodules()).__contains__
isbinmodule = frozenset(sys.builtin_module_names).__contains__
# this part after saveas dialog returns
if islibmodule(name):
go = warn("This name matches a stdlib name in /Lib. If you run python in this directory, you will not be able to import the stdlib module. Continue?".)
elif isbinmodule(name):
go = warn("This name matches a builtin stdlib name. You will not be able to import this file. Continue?".)
else:
go = True
if go:
<save as requested>
else:
(get name again> # or put in while not go loop |
|
Date |
User |
Action |
Args |
2015-10-31 05:41:43 | terry.reedy | set | recipients:
+ terry.reedy, markroseman, lac |
2015-10-31 05:41:42 | terry.reedy | set | messageid: <1446270102.89.0.424617028731.issue25522@psf.upfronthosting.co.za> |
2015-10-31 05:41:42 | terry.reedy | link | issue25522 messages |
2015-10-31 05:41:41 | terry.reedy | create | |
|