[Grok-dev] Re: MultiAdapter doc bug?
Brandon Craig Rhodes
brandon at rhodesmill.org
Tue Jun 24 21:11:25 EDT 2008
Martijn Faassen <faassen at startifact.com> writes:
> Tim Terlegård wrote:
>> On Jun 24, 2008, at 11:01 AM, Philipp von Weitershausen wrote:
>>> Tim Terlegård wrote:
>>>>
>>>> >>> home = IHome((cave, fireplace))
>
> Brandon has been proposing it ... The proposal was changed to
> something different-looking in that discussion, though.
The change was because people pointed out that there do exist adapters,
in some people's applications at least, which adapt <type tuple> to
something else. When you say,
home = IHome((cave, fireplace))
you are, strictly speaking, asking that a tuple be adapted to the IHome
interface, and everyone agreed that this is sensible and should be
allowed; therefore, the tuple cannot be used to say "multi-adaptation!".
Instead, we negotiated that a default value would *have* to be supplied
with a "default=" keyword argument, *not* with a second argument, like:
home = IHome(cave, default=None)
Once the default is moved to a keyword argument instead of an optional
second argument, multi-adaptation can be done like:
home = IHome(cave, fireplace)
or:
home = IHome(cave, fireplace, default=None)
Obviously this would break nearly the entire Zope code base, so the
proposal was to write an .adapt() method on Interface that takes the
new-style arguments for people who wanted to use them; and maybe then
rewrite everything to use adapt, then redefine __call__ to work the same
way, then remove .adapt() or make it the same as __call__.
And, as Martijn says, the first step is for me to sit down and write a
branch of grok.interface or grok.component (or both?) that defines the
new .adapt() method. The problem last year was that, even after looking
a bit at the code, I didn't really understand it well enough to add the
extension. I'll look again and see if things make more sense.
I remember that there are single adapters; multi adapters; for both,
there are named adapters in addition to the usual anonymous ones; each
kind of adaptation should be able to accept a default= argument; and
... there was *something* else that I didn't understand at all, and it's
what got in my way, and it's what kind of stopped me cold. Was it
utilities and whether they can be name or not? I can't remember.
--
Brandon Craig Rhodes brandon at rhodesmill.org http://rhodesmill.org/brandon
More information about the Grok-dev
mailing list