Hi,

I hope that his hasn't been discussed to death in the past but I quite often 
encounter cases where developers have unwittingly created a file or directory 
that has a name clash with either a system import or a pip installed library 
import. This can be very confusing to new users! And, of course, as the number 
of core libraries and the installable ecosystem grow this potential problem  is 
growing all of the time.

I know that we have use absolute imports to force importing local packages but 
I personally would like to have a notation to allow me to specify:


  1.  Import this name from the python system libraries only
  2.  Import this name from installed libraries only
  3.  Import this mane from the current project, i.e. the local directory or 
those above it
  4.  Import this name from local package only, i.e. only the current directory 
I know that this is possible with the .name notation but a lot od people seem 
to struggle with it
  5.  Import this name from wherever you can find it

In C/C++ projects that I have worked on it has been possible to do something 
similar, (providing the correct include flags have been set in the build 
environment), by distinguishing between `#include <name>` and `#include "name"` 
where the first will only consider system libraries and the latter only local.

I am not sure of what the notation would look like, (and of course the user 
would still have to take steps to avoid namespace clashes), but possibly 
something like:

```
from python import os, sys, glob  # Only system libraries as candidates
from installed import fred
from local import os as myos  # Personally I think that this would be clearer 
than from .package install ...
import some_other_package # The current behaviour
```

Hopefully nobody would have a file or directory called os but you never know.


Throwing this idea out there for discussion.

Steve (Gadget) Barnes

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/SUMWYJ5JHGJ2UDS2F5KFSCLHCJGW7LWU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to