New submission from Terry J. Reedy: 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 ---------- messages: 253775 nosy: lac, markroseman, terry.reedy priority: normal severity: normal stage: needs patch status: open title: IDLE: warn if save-as name matches stdlib name type: enhancement versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25522> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com