Skip to content

Commit

Permalink
refactor: limit special-case handling to 'InterfaceBase'
Browse files Browse the repository at this point in the history
Member descriptor behavior is tricky across Python versions, and across
static vs. heap-allocated types.  The 'InterfaceBase' base type is a
singleton, and has a known/desired "implements name".
  • Loading branch information
tseaver committed Jun 12, 2024
1 parent bc55fcb commit 61a84a1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/zope/interface/declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class implements (that instances of the class provides).

from zope.interface._compat import _use_c_impl
from zope.interface.interface import Interface
from zope.interface.interface import InterfaceBase
from zope.interface.interface import InterfaceClass
from zope.interface.interface import NameAndModuleComparisonMixin
from zope.interface.interface import Specification
Expand Down Expand Up @@ -364,12 +365,13 @@ def _implements_name(ob):
# It might be nice to use __qualname__ on Python 3, but that would produce
# different values between Py2 and Py3.

# Workaround: some C-based interfaces return a 'member_descriptor' for
# their '__module__'.
mod = getattr(ob, '__module__', None)
if not isinstance(mod, str):
mod = getattr(mod, '__name__', '?')
return mod + '.' + (getattr(ob, '__name__', '?') or '?')
# Special-case 'InterfaceBase': its '__module__' member descriptor
# behaves differently across Python 3.x versions.
if ob is InterfaceBase:
return 'zope.interface.interface.InterfaceBase'

return (getattr(ob, '__module__', '?') or '?') + \
'.' + (getattr(ob, '__name__', '?') or '?')


def _implementedBy_super(sup):
Expand Down

0 comments on commit 61a84a1

Please sign in to comment.