21 lines
570 B
Python
21 lines
570 B
Python
|
class NoopIsANoopException(TypeError):
|
||
|
""" Raised if the nooper decorator is unnecessary on a class. """
|
||
|
pass
|
||
|
|
||
|
|
||
|
def nooper(cls):
|
||
|
""" Decorates a class that derives from an ABCMeta, filling in any unimplemented methods with
|
||
|
no-ops.
|
||
|
"""
|
||
|
def empty_func(self_or_cls, *args, **kwargs):
|
||
|
pass
|
||
|
|
||
|
empty_methods = {}
|
||
|
for method in cls.__abstractmethods__:
|
||
|
empty_methods[method] = empty_func
|
||
|
|
||
|
if not empty_methods:
|
||
|
raise NoopIsANoopException('nooper implemented no abstract methods on %s' % cls)
|
||
|
|
||
|
return type(cls.__name__, (cls,), empty_methods)
|