[Zope3-dev] Re: [Zope3-checkins] CVS: Zope3/lib/python/Zope/ContextWrapper/tests - testSimpleMethodWrapper.py:1.8

Jeremy Hylton jeremy@zope.com (Jeremy Hylton)
Tue, 3 Dec 2002 17:05:25 -0500


>>>>> "SA" == Steve Alexander <steve@cat-box.net> writes:

  SA> + def __getitem__(wrapped_self, a, b=None):
  SA> + wrapped_self.result = wrapped_self, a, b
  SA> + return a
  SA> + __getitem__ = ContextMethod(__getitem__)
  SA> +
  SA>      def thisIsNotAContextMethod(self, val=None):
  SA>          self.result = self return val
  SA> @@ -69,6 +74,11 @@
  SA>          return a
  SA>      __call__ = ContextMethod(__call__)

This code deserves some decent variable names and maybe a comment or
two.

What are a and b?  __getitem__() only takes one argument, so I don't
get the optional argument.

We better explain that the reason we need an __getitem__ defined this
way is because __getattribute__ isn't invoked for __getitem__ when it
is accessed from C through the sequence or mapping API.

And what's that business about wrapped_self.result?  That seems like
it needs a comment, too.

I'm also wondering what we're going to do about all the other __
methods -- __setitem__, __delitem__, __len__, __iter__, __contains__.
I'm not sure which of these are mapped to slots in the type object,
but I'll bet a bunch of them are.

Jeremy