Skip to content

Commit

Permalink
Fix doctest by making sure the default type repr can be used.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Mar 17, 2020
1 parent 8ce0464 commit b745957
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/zope/interface/interface.py
Expand Up @@ -20,6 +20,7 @@
import weakref

from zope.interface._compat import _use_c_impl
from zope.interface._compat import PYTHON3 as PY3
from zope.interface.exceptions import Invalid
from zope.interface.ro import ro

Expand Down Expand Up @@ -421,8 +422,18 @@ def get(self, name, default=None):

return default if attr is None else attr

class _ModuleDescriptor(object):
class _ModuleDescriptor(str):
# type.__repr__ accesses self.__dict__['__module__']
# and checks to see if it's a native string. If it's not,
# the repr just uses the __name__. So for things to work out nicely
# it's best for us to subclass str.
if PY3:
# Python 2 doesn't allow non-empty __slots__ for str
# subclasses.
__slots__ = ('_saved',)

def __init__(self, saved):
str.__init__(self)
self._saved = saved

def __get__(self, inst, kind):
Expand All @@ -433,6 +444,9 @@ def __get__(self, inst, kind):
def __set__(self, inst, val):
inst.__ibmodule__ = val

def __str__(self):
return self._saved

# The simple act of having *any* metaclass besides type
# makes our __module__ shenanigans work. Doing this at the class level,
# and manually copying it around doesn't work.
Expand All @@ -444,7 +458,7 @@ def __new__(cls, name, bases, attrs):
_InterfaceClassBase = _MC(
'InterfaceClass',
(Element, InterfaceBase, Specification),
{'__module__': __name__})
{'__module__': __name__, '__qualname__': __name__ + 'InterfaceClass'})


class InterfaceClass(_InterfaceClassBase):
Expand Down

0 comments on commit b745957

Please sign in to comment.