[ZODB-Dev] API question

Marius Gedminas marius at gedmin.as
Mon Jan 14 20:33:25 UTC 2013


On Mon, Jan 14, 2013 at 01:32:07PM -0500, Tres Seaver wrote:
> While working on preparation for a Py3k port, I've stumbled across a
> fundamental issue with how ZODB structures its API.  Do we intend that
> client code do the following::
> 
>   from ZDOB import DB, FileStorage
>   db = DB(FileStorage('/path/to/Data.fs'))

ZODB.FileStorage is a module, you can't call it.

ZODB.DB, much to my surprise, refers to the ZODB.DB.DB class.  A
backwards compatibility thing maybe?

> or use the module as a facade ::
> 
>   import ZODB
>   db = ZODB.DB(ZODB.FileStorage.FileStorage('/path/to/Data.fs'))

This rings warning bells in my mind: if you're using the
ZODB.FileStorage module, you should import it directly:

    import ZODB
    import ZODB.FileStorage
    db = ZODB.DB(ZODB.FileStorage.FileStorage('/path/to/Data.fs'))

> I would actually prefer that clients explicitly import the intermediate
> modules::
> 
>   from ZDOB import DB, FileStorage
>   db = DB.DB(FileStorage.FileStorage('/path/to/Data.fs'))

(I'm not a fan of this style, but never mind that.)

> or even better::
> 
>   from ZDOB.DB import DB
>   # This one can even be ambiguous now
>   from ZODB.FileStorage import FileStorage
>   db = DB(FileStorage('/path/to/Data.fs'))

This is what I usually do.


I don't get the ambiguous comment.  ZODB.DB is (currently) always the
class[1].  ZODB.FileStorage is always the module.

  [1] I think (currently) the only way to refer to the ZODB.DB module is
  to use sys.modules['ZODB.DB']:

    >>> import ZODB
    >>> ZODB.DB
    <class 'ZODB.DB.DB'>

    >>> from ZODB import DB
    >>> DB
    <class 'ZODB.DB.DB'>

    >>> import ZODB.DB
    >>> ZODB.DB
    <class 'ZODB.DB.DB'>

> The driver for the question is getting the tests to pass under both
> 'nosetests' and 'setup.py test', where the order of module imports etc.
> can make the ambiguous cases problematic.  It would be a good time to do
> whatever BBB stuff we need to (I would guess figuring out how to emit
> deprecation warnings for whichever variants) before releasing 4.0.0.

Can you demonstrate the ambiguity?  As I've shown before, I was unable
to find it, at least with Python 2.x.

Marius Gedminas
-- 
We don't really understand it, so we'll give it to the programmers.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://mail.zope.org/pipermail/zodb-dev/attachments/20130114/8dc3644c/attachment.sig>


More information about the ZODB-Dev mailing list