[ZODB-Dev] Re: [Zope3-dev] Persistent module notes and proposal
Jim Fulton
jim at zope.com
Mon Jan 5 18:09:16 EST 2004
Casey Duncan wrote:
> On Mon, 05 Jan 2004 16:36:24 -0500
> Jim Fulton <jim at zope.com> wrote:
> [...]
>
>>>
>>>If I have the following in a module named "bar":
>>>
>>>foo = [1,2,3]
>>>
>>>and in a module named splat I do:
>>>
>>>from bar import foo
>>>
>>>Then I change the source of bar to:
>>>
>>>foo = [0,1,2,3]
>>>
>>>Does the value of "foo" imported in splat also change and when (Next
>>>transaction, etc)?
>>
>>
>>No. Don't do that. :)
>
>
> Good to know ;^)
>
>
>>If you wanted to share a list that way, you'd need to make
>>it a persistent list.
>>
>>I'm inclined to disallow import of non-persistent objects
>>from persistent modules.
>
>
> I agree. So classes and functions in persistent modules are persistent
> automagically?
Yes. There's a mapping step that happens after module execution
in which we map regular classes, functions, and interfaces to persistent ones,
updating existing values as appropriate to make imported refernces do the
right thing.
> [...]
>
>>>I continue to agree. So we either need to make it impossible to
>>>mutate module state (seems unlikely) or somehow make it clear that
>>>it is not a supported use or do nothing and expect many people to
>>>naively do the wrong thing and let them lose.
>>
>>Yup. A possibility is to really only allow a few types (e.g.
>>interfaces, classes, functions, tuples, strings, etc.)
>
>
> That sounds good except my example above would still be a gotcha, no
> (just change the list to a tuple)?
>
> In the example I'm not mutating the list, just changing its static
> definition in the module.
Right, but we might not let another module import it.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the ZODB-Dev
mailing list