summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2020-03-10 14:17:28 -0500
committerJason Madden <jamadden@gmail.com>2020-03-18 12:26:35 -0500
commitb9165b790c831b6d8a87a3f27d4f135143494ff8 (patch)
treecd44cae04f65368e9c5b909eeede7cb14827cd2b
parent8ac3bd088d9b924cfb3170b77b41effd2de39d23 (diff)
downloadzope-interface-b9165b790c831b6d8a87a3f27d4f135143494ff8.tar.gz
Fix doctest by making sure the default type repr can be used.
-rw-r--r--src/zope/interface/interface.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/zope/interface/interface.py b/src/zope/interface/interface.py
index 8707b9e..1ed1b6f 100644
--- a/src/zope/interface/interface.py
+++ b/src/zope/interface/interface.py
@@ -20,6 +20,7 @@ from types import FunctionType
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 as calculate_ro
from zope.interface import ro
@@ -485,8 +486,18 @@ class Specification(SpecificationBase):
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):
@@ -497,6 +508,9 @@ class _ModuleDescriptor(object):
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.
@@ -508,7 +522,7 @@ class _MC(type):
_InterfaceClassBase = _MC(
'InterfaceClass',
(Element, InterfaceBase, Specification),
- {'__module__': __name__})
+ {'__module__': __name__, '__qualname__': __name__ + 'InterfaceClass'})
class InterfaceClass(_InterfaceClassBase):