On 5 June 2017 at 22:25, Nathaniel Smith <n...@pobox.com> wrote: > On Mon, Jun 5, 2017 at 4:14 AM, Nick Coghlan <ncogh...@gmail.com> wrote: >> The biggest problem with this approach is that it means that adding >> new standard library modules becomes a backwards compatibility break - >> scripts that used to work will now fail since they'll get the standard >> library module rather than the previously implicit main relative >> import. At the moment we don't have that problem - as with new >> builtins, adding a new standard library module may mean people have to >> rename things to get access to it, but their current code won't >> actually *break* as a result of the new name being assigned. > > Python is a bit inconsistent about this. The standard library > currently doesn't shadow modules in the script directory, but it does > shadow site-packages, which means that new stdlib modules already can > break working code. It also makes it impossible to pip install > backport modules that intentionally shadow old stdlib modules, which > might not be a great idea but is at least plausibly useful in some > situations, while the kind of accidental shadowing one gets in the > script directory is pretty much always bad IME.
And if folks want to *reliably* shadow the standard library (whether with their own modules or with third party ones), we already have a solution for that: zipapp and "pip install --target .". You do need to rename your scripts in development from "script.py" to "script/__main__.py" if you want to go down that path, though. I'm still somewhat inclined towards special casing __main__.__spec__.origin, but the point about standard library additions already shadowing site-packages does move me to being +0 on changing the relative precedence of the current directory on sys.path, rather than my previous -1. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/