[Zope-dev] zope.component: calling an Interface and calling queryAdapter give differing results

Dieter Maurer dieter at handshake.de
Sat Aug 23 07:15:52 EDT 2008


Chris Withers wrote at 2008-8-19 18:30 +0100:
> ...
> >>> class ISomething(Interface): pass
>...
> >>> class MyClass: implements(ISomething)
>...
> >>> m = MyClass()
>
>Right, so this does make sense:
>
> >>> ISomething(m)
><__main__.MyClass instance at 0x00BED6E8>
>
>This does not:
> >>> repr(queryAdapter(m,ISomething))
>'None'
>
>why the difference?

Jim is heavily defending this difference.

I am convinced that the difference should not be there
but meanwhile have found a use case for it.

  Suppose, you have a class "C" that implements "I".

  If "queryAdapter" would behave like "I(...)", you
  would have no way to override the implementation
  of "I" by "C".

  With the current behavior, you can use
  "queryAdapter(c, I)" to check whether some special
  requirements apply and in this case use the special purpose
  adapter.

Not that this use case had been able to convince me that
the difference were justified.



-- 
Dieter


More information about the Zope-Dev mailing list