Last active
August 3, 2018 16:33
-
-
Save natelust/4ba461beb03b00d87d73d2b24b6aa114 to your computer and use it in GitHub Desktop.
Python function to create a dummy classes from real classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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