Skip to content

Instantly share code, notes, and snippets.

@natelust
Last active August 3, 2018 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natelust/4ba461beb03b00d87d73d2b24b6aa114 to your computer and use it in GitHub Desktop.
Save natelust/4ba461beb03b00d87d73d2b24b6aa114 to your computer and use it in GitHub Desktop.
Python function to create a dummy classes from real classes
def _dummyFactory(cls):
"""Python function to wrap a class in a dummy implementation
Dummy classes created with this function will have all the
same methods and attributes of the class they wrap, but will
always evaluate to None. Attributes will be None in value,
methods will be callable, but they will always return None.
Parameters
----------
cls : Class
Class to be wrapped in dummy implementation
Returns
-------
dummyClass : Class
Wrapped input class
"""
name = "Dummy"+cls.__name__
def __getattr__(self, attr):
if callable(getattr(cls, attr)):
def methodWrapper(*args, **kwargs):
return None
return methodWrapper
else:
return None
return type(name, (cls,), {'__getattribute__': __getattr__})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment