[Zope-CMF] CMFDefault.utils is not monkey-patchable
Tres Seaver
tseaver@zope.com
13 Nov 2002 22:58:53 -0500
On Wed, 2002-11-13 at 18:37, Paul Winkler wrote:
> On Wed, Nov 13, 2002 at 09:16:07AM -0800, Paul Winkler wrote:
> (snip)
> > ... So all the lines in __init__.py
> > of the form utils.initializeBasesPhase2(...)
> > could be safely replaced with
> > CMFCore.utils.initializeBasesPhase2(...)
> >
> > I will change this locally and see if it hurts anything,
> > and report back.
>
> Seems to be fine.
> below is a diff against CMFDefault/__init__.py for
> anyone who's interested.
>
> --Paul Winkler
>
>
> 31c31,33
> < from Products.CMFCore import utils
> ---
> > #from Products.CMFCore import utils # BAD ... it masks CMFDefault.utils
> > from Products import CMFCore
OK, I finally see your point here. Importing an entire module from
another package is the Wrong Thing (TM), especially if it hides a
local module. I will commit this change myself (in the future, note
that the preferred diff format is unidiff, with context running a
distant second; "traditional" diffs are much harder for humans
to parse. :)
The other case, where "leaf" names are imported, is much more benign
(because they aren't namespaces themselves). In fact, it is a
"recommended practice" for Zope3. E.g.::
from Products.CMFCore.utils import getToolByName
No way do I want to invoke that everywhere as::
Products.CMFCore.utils.getToolByName( context, 'portal_foo' )
While we are at it, I (now) prefer to export interfaces directly
(without sub-package qualifiers) from their "main" package. E.g.,
in package FooStuff's __init__.py::
from interfaces.IQux import IQux
Clients then just import as:
from FooStuff import IQux
Note that the 'IQux' in FooStuff's namespace does *not* shadow the
module in which IQux is declared (which would happen if it were in
the "top" level of the package).
Thanks for the patch!
Tres.
--
===============================================================
Tres Seaver tseaver@zope.com
Zope Corporation "Zope Dealers" http://www.zope.com