Skip to content

Instantly share code, notes, and snippets.

@johnberroa
Last active October 11, 2019 15:05
Show Gist options
  • Save johnberroa/a4eac050e759ba868ba2f9f609bed793 to your computer and use it in GitHub Desktop.
Save johnberroa/a4eac050e759ba868ba2f9f609bed793 to your computer and use it in GitHub Desktop.
Replace any class with this to essentially disable all references to it in code. Use this instead of many try/excepts or ifs.
class Disabled:
"""Class that absorbs all attribute and method calls on it"""
def __init__(self, *args, **kwargs):
pass
def __getattr__(self, item):
return self
def __call__(self, *args, **kwargs):
return self
def __getitem__(self, item):
return self
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
return self
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment