summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTres Seaver <tseaver@palladion.com>2017-09-01 12:08:35 -0400
committerGitHub <noreply@github.com>2017-09-01 12:08:35 -0400
commitfc5414c87af90c331463269be8f1a53fd65dc511 (patch)
tree99b0bd57463bcdfb9cf6dd2bcdb15754032b6e3b
parenta34e5cbaa8359d859af9f1d572d3b1c34a1466a1 (diff)
parent5162674b83d549e276f87cc22cb68c867955a94d (diff)
downloadzope-interface-fc5414c87af90c331463269be8f1a53fd65dc511.tar.gz
Merge pull request #99 from avanov/master
Drop `__annotations__` in interface declarations, added to interface definitions with Python 3.x type hints.
-rw-r--r--CHANGES.rst3
-rw-r--r--src/zope/interface/interface.py3
-rw-r--r--src/zope/interface/tests/test_interface.py9
3 files changed, 13 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 2cd6671..fedcfaa 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,7 +4,8 @@ Changes
4.4.3 (unreleased)
------------------
-- Nothing changed yet.
+- Avoid exceptions when the ``__annotations__`` attribute is added to interface definitions with Python 3.x type hints.
+ See `issue 98 <https://github.com/zopefoundation/zope.interface/issues/98>`_.
4.4.2 (2017-06-14)
diff --git a/src/zope/interface/interface.py b/src/zope/interface/interface.py
index e44f93f..d1df7dd 100644
--- a/src/zope/interface/interface.py
+++ b/src/zope/interface/interface.py
@@ -352,9 +352,10 @@ class InterfaceClass(Element, InterfaceBase, Specification):
# Make sure that all recorded attributes (and methods) are of type
# `Attribute` and `Method`
for name, attr in list(attrs.items()):
- if name in ('__locals__', '__qualname__'):
+ if name in ('__locals__', '__qualname__', '__annotations__'):
# __locals__: Python 3 sometimes adds this.
# __qualname__: PEP 3155 (Python 3.3+)
+ # __annotations__: PEP 3107 (Python 3.0+)
del attrs[name]
continue
if isinstance(attr, Attribute):
diff --git a/src/zope/interface/tests/test_interface.py b/src/zope/interface/tests/test_interface.py
index 58ed808..2bb3d1c 100644
--- a/src/zope/interface/tests/test_interface.py
+++ b/src/zope/interface/tests/test_interface.py
@@ -460,6 +460,15 @@ class InterfaceClassTests(unittest.TestCase):
self.assertEqual(inst.__bases__, ())
self.assertEqual(inst.names(), ATTRS.keys())
+ def test_ctor_attrs_w___annotations__(self):
+ ATTRS = {'__annotations__': {}}
+ klass = self._getTargetClass()
+ inst = klass('ITesting', attrs=ATTRS)
+ self.assertEqual(inst.__name__, 'ITesting')
+ self.assertEqual(inst.__doc__, '')
+ self.assertEqual(inst.__bases__, ())
+ self.assertEqual(inst.names(), ATTRS.keys())
+
def test_ctor_attrs_w__decorator_non_return(self):
from zope.interface.interface import _decorator_non_return
ATTRS = {'dropme': _decorator_non_return}