Hello everyone:

The scenario/observation:
Beginners sometimes create scripts with the name of a package e.g. pandas.py or seaborn.py in order to test something.
Later, they create and run another script or Jupyter Notebook in the same folder which contains e.g. "import seaborn as sns" where the import itself (most often) succeeds. However - and you see that coming already - when they try to use attributes of the module, this fails with an AttributeError and the poor souls don't know what happened and are not familiar and confident enough to walk the traceback to find out that the import was resolved by the local seaborn.py file instead of the installed seaborn module/library. They are blocked until they have access to a senior Pythonista who helps them out with that or they understand the Stackoverflow advice even though they think the solution should come from a different direction. Either way, it does not make Python seem seamless and intuitive to them. (And the next time around, they might have forgotten about this idiosyncrasy and go through the loop again - especially if they don't code on a daily basis which - in my experience - is the fact for a significant number of casual Python users.)

The problem:
Their internal mental model / expectation is that this import name should (first) relate to the installed library - rather than the local file that happens to live in the (often messy) same folder.

Having said that, I guess that this has been discussed already in the past and I am curious about any pointers to discussions of the past. (I searched for "import order modules" in the archive and could not find something similar in the first 10 results.)

Have a great day,

I guess, one potential solution would be to change the import resolution order. But of course, this is a breaking change (at least in implicit semantics - not sure if it will actually lead to too many real-world problems - but probably there will be some) and might only be feasible in a safe way in a new major version? (Or even in a minor version but with other flags or imports from "the past" instead of "future" that restore the old behavior if that is actually important for some users?)