08.12.20 22:14, M.-A. Lemburg пише:
On 08.12.2020 20:47, Gregory Szorc wrote:
Anyway, I was encouraged by Brett Cannon to email this list to assess the appetite for introducing a backwards incompatible change to this behavior. So here's my strawman/hardline proposal:
1. 3.10 introduces a DeprecationWarning for "__init__" appearing as any module part component (`"__init__" in fullname.split(".")`). 2. Some future release (I'm unsure which) turns it into a hard error.
-1 on this proposal. We don't want to needlessly break code just because they use a feature of the existing implementation, which has been around for decades.
This feature has some bad side effects. Also, it does not look like this feature was added intentionally, otherwise we would handle these side effects.
Moreover, if you use namespace packages, a module __init__.py does not have to exist in the directory, so importing pkg.__init__ is a way to test for such a case.
Why do you need to test such a case? And are there other ways, without such side effects? I never seen a code try: import mypackage.__init__ except ImportError: # do something else: # do something else (But on other hand, I did not see importing from __init__ as well before OP opened the issue.)
(A less aggressive proposal would be to normalize "__init__" in module names to something more reasonable - maybe stripping trailing ".__init__" from module names. But I'll start by proposing the stricter solution.)
-0 on this, since it may break code. If done, Python should issue a warning to flag the issue.
Actually, making package.__init__ an alias of package would mitigate the issue. But I am not sure we need such feature.
Third solution: leave things as they are and document it.
+1 on this one, since it's been like this for ages (going way back to the Python 1.x days).
It was my first reaction. Just say "Don't do this". But many people does not read documentation and does not use linters, so it makes sense to add a warning which can force them to read explanation in the documentation (or at least ask a question on forum).