This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/util/abchelpers.py

20 lines
571 B
Python
Raw Normal View History

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.
"""
2017-04-20 17:42:49 +00:00
def empty_func(*args, **kwargs):
# pylint: disable=unused-argument
pass
2017-04-20 17:42:49 +00:00
empty_methods = {m_name: empty_func for m_name in cls.__abstractmethods__}
if not empty_methods:
raise NoopIsANoopException('nooper implemented no abstract methods on %s' % cls)
return type(cls.__name__, (cls,), empty_methods)