[Zope3-dev] Nasty bugs

Steve Alexander steve@cat-box.net
Wed, 20 Mar 2002 08:36:22 +0000


Guido van Rossum wrote:
> 
>     (2a) Why would None need to be wrapped?

This opens up a larger problem, and one which Shane and I have been 
discussing at some length on IRC.

If None is wrapped, we can't expect to use Zope3 directly with 
third-party modules that say:

   if foo is None:

...as, a wrapped None is not None.


There's a similar issue around other wrapped primitive types. For 
example, I recently (with Fred's reluctant blessing) checked in a change 
to TALDefs.py to stop it checking that a macro is a list, using instanceof.

This was breaking Page Template macros in Zope 3 because the list would 
be wrapped, and instanceof(wrapped_list, ListType) is 0.


(There's another issue here, of why a macro is a list rather than a 
PageTemplateMacro instance.)

Fred also recently fixed a bug in wrapper.c, where:

   for a in Wrapper([1,2,3]): print a

... would fail, because wrappers didn't fill the appropriate iterable 
slot. This bug, in conjunction with wrapping PageTemplate Macros, was 
causing the ZMI not to work.


I see a few choices here:

   1: Zope3 puts constraints on modules it is used with such that they
      don't use "is", "type" or "instanceof" on anything they don't have
      full and immediate control over.

   So, modules to be used with Zope3 should use
   interface.isImplementedBy, which should be changed to know about
   wrappers.
   This seems to go against Zope3's goal of easily interoperating with
   3rd party python modules.


   2: Primitive types are never wrapped.

   This is not such a good idea for security, especially if we're passing
   around complex structured data (such as in a Page Template Macro).
   So, this also conflicts with the Zope3 interoperability goal above.
   Also, I can see this being a problem for the SpaceSuits capability-
   based security proposal.


   3: Python is altered to support very transparent wrappers.

   So, there's some sort of "I'm a wrapper" slot, and type and isinstance
   and "is" know about this slot and compare unwrapped values.

   I don't know if this is desirable for type and isinstance, and I don't
   know if it is possible for "is".

--
Steve Alexander