Skip to content

Instantly share code, notes, and snippets.

@vl3
Created August 5, 2019 00:04
Show Gist options
  • Save vl3/e66cb88a48117eb53388d83aaaf6bd72 to your computer and use it in GitHub Desktop.
Save vl3/e66cb88a48117eb53388d83aaaf6bd72 to your computer and use it in GitHub Desktop.
Feature toggle
class FeatureToggle(object):
def __init__(self, old, new, toggle):
self.old = old
self.new = new
self.toggle = toggle
def __getattr__(self, name):
def wrapper(*args, **kwargs):
instance_to_use = self.new if self.toggle else self.old
return getattr(instance_to_use, name)(*args, **kwargs)
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment