Sorry if I wasn’t clear. I mean that the problem you are talking about (that sys.path hacks can allow someone to import the same module twice), and the problem I’m talking about (that relative imports don’t work at top-level) are entirely independent problems. The former isn’t the general problem; if it were completely solved, then it wouldn’t affect the latter at all. And vice versa.
Of course, I agree with you that if there is a general problem to solve, it’s usually better to solve that general problem rather than do half measures. It’s just that that’s not what’s going on here.
In my proposed solution, all the rules for relative imports and their associated errors are identical. That is, arbitrary relative imports are allowed within a package, but only within that package. In particular, since site_packages is not itself a package, my solution has zero changes for how people interact with it.
Using my proposed solution, if I’m working on a package a that has four files: __init__.py, the script, y.py and x.py. Then y.py can’t do import a.x because a isn’t the name of a package (precisely the same as it currently is). But y.py could do from . import x. This would be added to sys.modules as ".x".
To be clear, I will restate my proposed idea from above: if a sys.path has some identifying file (e.g. __init__.py), treat it as an anonymous package for relative imports. You could call what I’m proposing “anonymous top-level packaging”.
I’m not opposed to simply updating documentation/communication, but I think that there seems to be legitimate cases where it makes sense to allow these relative imports.
Let’s take the examples I linked at the start. They had their source code in one folder, and their tests in another folder. That’s a very common pattern, and it doesn’t work without some sys.path hacks or creative commandline calls. Are they doing something wrong? The answers to those linked questions doesn’t have anyone saying that what they are trying to do is fundamentally wrong, just that python doesn’t support it very well.
So, what’s wrong with those cases? What should they do instead?