Re: improving the utility and adapter lookup APIs

Marius Gedminas <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <20091127112702.GA27462@platonas>
On Thu, Nov 26, 2009 at 11:09:35AM -0500, Benji York wrote:
> On Thu, Nov 26, 2009 at 9:04 AM, Leonardo Rochael Almeida
> <[email protected]> wrote:
> > On Thu, Nov 26, 2009 at 14:34, Benji York <[email protected]> wrote:
> >> On Wed, Nov 25, 2009 at 11:17 AM, Matthew Wilkes
> >>> I know it's probably a spurious use case, but what if I want to adapt a
> >>> tuple?
> >>
> >> There could be an optional keyword argument to be explicit.
> >>
> >> This would be a single-adapter lookup:
> >>
> >> IFoo(from=my_tuple)
> >
> > You probably already realized it by now, but this is a syntax error
> > (remember: "from module import name").
> 
> Nope, it hadn't occurred to me.  Some other argument name could be used
> instead.

Why do you need an argument when you can wrap the tuple in a tuple?

  IFoo((my_tuple, ))

This is what people currently have to do when they use

  "Here's an object I know nothing about: %r" % (obj, )

(Personally, I find that ugly and always use "text: %s" % repr(obj))

> >> While this would be a multi-adapter lookup:
> >>
> >> IFoo(my_tuple)
> >
> > To take my stab at this bikeshed painting, and since it doesn't seem
> > likely we'd want to break backward compatibility, I think I'd prefer
> > the other way around:
> >
> > IFoo(multi=my_tuple)
> >
> > and leave the first parameter for single adaptation, although what I'd
> > really prefer is multi-adaptation on multiple positional parameter.
> 
> I'd rather have the common case (of adapting a non-tuple) be the simpler
> form and the exception (adapting a tuple) require more verbiage.

That would be fine if you always knew what objects you were adapting.
Now, to be safe, you always have to use the "special" verbose syntax in
generic code.

-1 for making generic code ugly.

Marius Gedminas
-- 
http://pov.lt/ -- Zope 3 consulting and development

_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iD8DBQFLD7eDkVdEXeem148RAlQfAKCKsGpLqHiZhlbJTnLOjTN4+c+JjQCfa4Kg
OjazXERk1jGeNs1D4QqubHM=
=W4J9
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.