On Fri, Jun 2, 2017 at 11:05 AM, Steven D'Aprano <st...@pearwood.info> wrote: > On Fri, Jun 02, 2017 at 09:22:16AM +1000, Chris Angelico wrote: > >> Ultimately, what I would like is for "import random" to be absolutely >> dependably going to grab the stdlib "random" module, or at very least, >> something that someone *deliberately* is shadowing that module with. >> You shouldn't be able to accidentally shadow a stdlib module. > > If that's the only problem you want to solve, then I would expect that > moving the script/current directory to the *end* of sys.path instead of > the start will accomplish that, without breaking any scripts that rely > on '' to be in the path. > > I expect that moving '' to the end of sys.path will be a less disruptive > change than removing it.
This is true. However, anything that depends on the current behaviour (intentionally or otherwise) would be just as broken as if it were removed, and it's still possible for "import foo" to mean a local import today and a stdlib import tomorrow. It'd just move the ambiguity around; instead of not being sure if it's been accidentally shadowed, instead you have to wonder if your code will break when a future Python version adds a new stdlib module. Or your code could break because someone pip-installs a third-party module. You can take your pick which thing shadows which by choosing where you place '' in sys.path, but there'll always be a risk one way or another. Different packages don't conflict with each other because intra-package imports are explicit. They're safe. ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/