Open djay opened 4 years ago
Dylan Jay wrote at 2020-5-21 02:59 -0700:
There are times you want to override an adapter but use the fundtionality of the whatever else was registered that you overrode. This code allows you to do that. It would be very handy if this was added as a feature to zope.component, perhaps in a more efficient way? ...
I had a similar use case in Products.AdvancedQuery
.
There I need the concept "conditional adapter": an adapter typically
good but only if some condition is met. Otherwise, a more general
adapter should be used.
I implemented this concept based on "subscription adapter"s. The implementation uses that "subscription adapter"s are delivered in a specific order (when I remember right, most specific first).
Beginning in zope.interface 5, using super()
is now meaningful with adapter lookups. Perhaps that helps with this request?
Make
providedBy()
andimplementedBy()
respectsuper
objects. For instance, if classDerived
implementsIDerived
and extendsBase
which in turn implementsIBase
, thenprovidedBy(super(Derived, derived))
will return[IBase]
. Previously it would have returned[IDerived]
(in general, it would previously have returned whatever would have been returned without super).Along with this change, adapter registries will unpack
super
objects into their__self___
before passing it to the factory.Together, this means that
component.getAdapter(super(Derived, self), ITarget)
is now meaningful.
There are times you want to override an adapter but use the fundtionality of the whatever else was registered that you overrode. This code allows you to do that. It would be very handy if this was added as a feature to zope.component, perhaps in a more efficient way?