[Import-SIG] My objections to implicit package directories

PJ Eby pje at telecommunity.com
Mon Mar 19 19:52:05 CET 2012

On Mar 19, 2012 4:48 AM, "Nick Coghlan" <ncoghlan at gmail.com> wrote:
> For the record, I just thought of an easy workaround for the "erroneous
successful import" case: drop an __init__.py file containing "raise
ImportError" into the offending data directory.

It only works if you don't mind shadowing a later installation of the
same-named package, further along on sys.path.

More to the point, it doesn't solve the real problem, which is noticing in
the first place that this is happening.  The right way to fix it is to
change your try:"import foo" to "try:from foo import something"

(Unfortunately, even that fix isn't purely correct, since if there's a
foo/something subdirectory, you still get a false positive.  It just
further reduces the odds of a collision.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/import-sig/attachments/20120319/9aa8c6ed/attachment.html>

More information about the Import-SIG mailing list