[docs] [issue25294] Absolute imports fail in some cases where relative imports would work

Patrick Maupin report at bugs.python.org
Sun Oct 4 06:25:14 CEST 2015

Patrick Maupin added the comment:

I'm a big fan of stitching things together at the top myself -- maybe that's partly an unconscious reaction to this very issue.

But I'm not sanguine about how easy it is to express this practice in the docs.

This issue arose in the context of me answering a question on Stack Overflow.  My initial response was "well, duh, obviously relative imports are more Pythonic here because that's the obvious way to do it (that works)."

But then, of course, PEP 8 disagrees.

For that actual question on Stack Overflow, you would have to carefully define the scope of "executing" so that it was fully understood to include "subclassing a class defined in a peer module or submodule" -- because that's what was breaking.

Just as most people don't think of imports that can be placed in a DAG as circular, most people also don't think of subclassing as "executing."

But the Python interpreter sometimes vehemently disagrees in both cases.  I'm not surprised at its behavior, but I'm also not surprised that some people who haven't thought deeply about the behavior find it surprising.

I'm not fully convinced that this even can be documented in a way that renders observed behavior unsurprising in the general case, but I am convinced that doing so would require a lot of care.


Python tracker <report at bugs.python.org>

More information about the docs mailing list