[Zope-dev] Coding style clarifications
Martijn Faassen
faassen at startifact.com
Fri Feb 20 12:18:48 EST 2009
Hi there,
Jim Fulton wrote:
[snip]
>> I suspect there are two possibilities:
>>
>> * no API defined in __init__.py and absolute imports
>>
>> * API defined in __init__.py and dotted.package.name.references
>> don't work.
>
> In what way don't they work?
> I don't see how this has anything to do with from imports. Putting an
> API in the package __init__ just makes object paths shorter. I don't
> see how the location of an API has much bearing on whether to use from
> imports or not.
You generate circular imports if a package that does this has modules
that contain absolute dotted imports from the same package, as I
described elsewhere. If you use from imports in the modules in the
package it does work. For imports of stuff that is external to the
package it usually shouldn't matter (unless I guess there's a circular
dependency between packages).
What causes this exactly caused us quite a bit of headscratching back at
the sprint, and a lot of theorizing, but if anything satisfactory came
out of that it's slipped my mind again. The interactions are quite
subtle and changing an import from one form to the other (and having
imports in __init__.py at all) can break it.
We discovered this when Christian Theune said he wanted his package
__init__.py empty as otherwise he runs into circular import issues. Some
of the others including myself were puzzled as we put APIs in
__init__.py quite frequently without such problems. Turned out it was
because he is using the same convention for imports you do, and we weren't.
Regards,
Martijn
More information about the Zope-Dev
mailing list