Warning when importing a local module with the same name as a 2nd or 3rd party module

As long as I didn’t misunderstand you, I don’t think that’s how this kind of bug can happen. Let’s say you distribute a package foo with a submodule scipy. Importing that module would be either with import foo.scipy, which won’t clash with import scipy, or from . import scipy within your package, with also won’t clash with import scipy.

It would only be a problem if your distribution manipulated sys.path in order to be able to import your scipy submodule with import scipy internally. At that point, it’s so far from best practices that it should break.

I think this kind of issue only really takes place if a user writes scripts, it’s a non-issue for libraries. And if someone has a script foo.py and installs your package, that’s exactly when you’d want to be warned about potential name clashes. Worst case, if you know what you’re doing you just ignore or suppress the warning.

edit: also, I’m not proposing to raise an Error, just to print a warning that is more helpful than the likely AttributeError/NameError/ImportError which follows right after.