Skip to content

Commit 07b8cac

Browse files
author
Scott Sanderson
committed
ENH: Don't allow instantiating interfaces.
1 parent 7c66455 commit 07b8cac

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

interface/interface.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class Interface(metaclass=InterfaceMeta):
144144
"""
145145
Base class for interface definitions.
146146
"""
147+
def __new__(cls, *args, **kwargs):
148+
raise TypeError("Can't instantiate interface %s" % getname(cls))
147149

148150

149151
empty_set = frozenset([])

interface/tests/test_interface.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,12 @@ def method3(self, a, b, c):
287287
OtherIFace.method3(self, a, b, c)"""
288288
)
289289
assert impl.__doc__ == expected_doc
290+
291+
292+
def test_cant_instantiate_interface():
293+
294+
class I(Interface): # pragma: nocover
295+
pass
296+
297+
with pytest.raises(TypeError):
298+
I()

0 commit comments

Comments
 (0)