Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normal metaclass resolution not applied to InterfaceClass #16

Closed
tseaver opened this issue Jan 12, 2015 · 3 comments
Closed

Normal metaclass resolution not applied to InterfaceClass #16

tseaver opened this issue Jan 12, 2015 · 3 comments
Labels

Comments

@tseaver
Copy link
Member

tseaver commented Jan 12, 2015

In https://bugs.launchpad.net/zope.interface/+bug/791218, @lrowe reported:

While experimenting with my InterfaceClass subclass I noticed that it was only being used when it was specified as the first of the bases. I believe this is because InterfaceClass is not a subclass of type, so the normal metaclass derivation logic is not applied. The branch at svn+ssh://svn.zope.org/repos/main/zope.interface/branches/elro-metaclass-resolution implements that logic in InterfaceClass.__new__, picking from the base metaclasses that metaclass which subclasses all other base metaclasses.

The motivating factor here is: I need an Interface with a hook that gets called after InterfaceClass.__init__ to allow for:

  • Checking that field names supplied as tagged values from directives correspond to actual field names to detect typos.
  • Registering the Interface instance for further configuration to be executed by a zope.configuration action.

Relevant changeset: http://zope3.pov.lt/trac/changeset/121497/zope.interface/branches/elro-metaclass-resolution

Example InterfaceClass subclass: http://dev.plone.org/plone/browser/plone.supermodel/branches/elro-directives/plone/supermodel/model.py#L58

@tseaver tseaver added the bug label Jan 12, 2015
@lrowe
Copy link

lrowe commented Jan 12, 2015

For my defence I can only plead that stubbornness led me to strange places...

@tseaver tseaver added wontfix and removed bug labels Dec 6, 2016
@tseaver
Copy link
Member Author

tseaver commented Dec 6, 2016

I'm going to reverse myself and say that this behavior is not-a-bug. @lrowe, if you can come up with a backward-compatible mechanism which solves your usecase, please submit a PR.

@tseaver tseaver closed this as completed Dec 6, 2016
@pbauer
Copy link
Member

pbauer commented May 4, 2017

@lrowe In Python 3 this seems to work as we found out while porting plone.supermodel:

>>> from zope.interface import Interface
>>> from zope.interface.interface import InterfaceClass
>>> class SpecialClass(InterfaceClass): pass
...
>>> Special = SpecialClass('Special')
>>> class I(Interface):
...     pass

>>> class S(Special):
...     pass

>>> class Combined(I, S):
...     pass

>>> isinstance(Combined, SpecialClass)
True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants