Repository: seequent/pure_interface

Issue:
PI does not work with __init_subclass__ with kwargs
See this case for the related ABC change that was made in 3.7: [https://bugs.python.org/issue29581](url)

Since __init_subclass__ landed into 3.6, it's now possible to define classes that support arbitrary keyword arguments in the class definition, like:

`class Foo(Bar, Baz=True):`

However, these kwargs need to be handled by __new__ and passed along (eventually) to init subclass.  Currently classes that are PIType do not support this and give a TypeError on declaration.

Simply patching new to pass the kwargs through seems to do the job:
[pi_kwargs.zip](https://github.com/seequent/pure_interface/files/3105569/pi_kwargs.zip)

Comments:

Patch:
diff --git a/.gitignore b/.gitignore
index 4fbf9db..4dc0b15 100644
--- a/.gitignore
+++ b/.gitignore
@@ -93,3 +93,9 @@ ENV/
 
 # PyCharm
 .idea/
+
+# MyPy
+.mypy_cache/
+
+# build output
+dist/
diff --git a/pure_interface.py b/pure_interface.py
index c3d38f8..511959e 100644
--- a/pure_interface.py
+++ b/pure_interface.py
@@ -40,7 +40,7 @@ else:
             super(abstractstaticmethod, self).__init__(callable)
 
 
-__version__ = '3.4.0'
+__version__ = '3.4.1'
 
 
 is_development = not hasattr(sys, 'frozen')
@@ -473,13 +473,13 @@ class PureInterfaceType(abc.ABCMeta):
         * if the type is a concrete class then patch the abstract properties with AttributeProperies.
     """
 
-    def __new__(mcs, clsname, bases, attributes):
+    def __new__(mcs, clsname, bases, attributes, **kwargs):
         # PureInterface is not in globals() when we are constructing the PureInterface class itself.
         has_interface = any(PureInterface in base.mro() for base in bases) if 'PureInterface' in globals() else True
         if not has_interface:
             # Don't interfere if meta class is only included to permit interface inheritance,
             # but no actual interface is being used.
-            cls = super(PureInterfaceType, mcs).__new__(mcs, clsname, bases, attributes)
+            cls = super(PureInterfaceType, mcs).__new__(mcs, clsname, bases, attributes, **kwargs)
             cls._pi = _PIAttributes(False, (), {}, ())
             return cls
 
@@ -546,7 +546,7 @@ class PureInterfaceType(abc.ABCMeta):
                                   'pi_partial_implementation attribute, not it''s value')
 
         # create class
-        cls = super(PureInterfaceType, mcs).__new__(mcs, clsname, bases, namespace)
+        cls = super(PureInterfaceType, mcs).__new__(mcs, clsname, bases, namespace, **kwargs)
         cls._pi = _PIAttributes(type_is_interface, abstract_properties,
                                 interface_method_signatures, interface_attribute_names)
 
diff --git a/setup.py b/setup.py
index d28b81f..1304da6 100644
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@ from setuptools import setup
 
 setup(
     name='pure_interface',
-    version='3.4.0',
+    version='3.4.1',
     py_modules=['pure_interface', 'pure_contracts'],
     url='https://github.com/aranzgeo/pure_interface',
     install_requires=['six', 'typing'],


Test patch:
diff --git a/tests/test_py3/test_impl3_checks.py b/tests/test_py3/test_impl3_checks.py
index c936bab..12b7404 100644
--- a/tests/test_py3/test_impl3_checks.py
+++ b/tests/test_py3/test_impl3_checks.py
@@ -22,3 +22,16 @@ class TestImplementationChecks(unittest.TestCase):
 
         self.assertIn('a', get_interface_attribute_names(IAnnotation))
         self.assertIn('b', get_interface_attribute_names(IAnnotation))
+
+    def test_works_with_init_subclass_kwargs(self):
+        saved_kwargs = {}
+
+        class ReceivesClassKwargs:
+            def __init_subclass__(cls, **kwargs):
+                super().__init_subclass__()
+                saved_kwargs.update(kwargs)
+
+        class Receiver(ReceivesClassKwargs, PureInterface, x=1, y=2, z=3):
+            pass
+
+        self.assertEqual(saved_kwargs, dict(x=1, y=2, z=3))