[docs] [issue25294] Absolute imports fail in some cases where relative imports would work
report at bugs.python.org
Mon Oct 5 23:05:42 CEST 2015
Patrick Maupin added the comment:
You are correct that I have conflated two issues, but they are not orthogonal -- if you choose to use relative imports, you will never encounter this issue, because your imports will all be of the 'from ... import' form.
(And, as you point out, the fact that you don't have this issue with absolute "from ... import" statements is due to some special-casing in the import logic that doesn't help the other kind of import statement.)
But PEP 8 denigrates relative imports, and then goes on to describe the use of the "import x.y.z; x.y.z.foo" form as a way to avoid name clashes.
So PEP 8 promotes absolute imports, and then it presents using "import" instead of "from ... import" as a solution to some problems. It never mentions that the 'as' clause could also solve those problems, and also never mentions that "import x.y.z" can actually cause problems in some cases.
And the importlib documentation is also a bit sparse on where things can fail.
We're in agreement that it will be difficult to document properly, and maybe I overstated my case, but my opinion remains that the current documentation promotes practices that _will_ sometimes get people in trouble.
Python tracker <report at bugs.python.org>
More information about the docs