Skip to content

Instantly share code, notes, and snippets.

@typemytype
Created January 25, 2017 20:59
Show Gist options
  • Select an option

  • Save typemytype/40f85e9cf1ecd0a85a59645a29f4a6b1 to your computer and use it in GitHub Desktop.

Select an option

Save typemytype/40f85e9cf1ecd0a85a59645a29f4a6b1 to your computer and use it in GitHub Desktop.
class Implementation(object):
def __init__(self, tag):
self._tag = tag
self._instance = None
def __getattr__(self, attr):
attr = "_%s_%s" % (self._tag, attr)
return getattr(self._instance, attr)
def __get__(self, instance, obj):
self._instance = instance
return self
class BaseContour(object):
def aMethod(self, point):
return "BaseContour aMethod", self, point
class BetaContour(BaseContour):
beta = Implementation("beta")
def _beta_aMethod(self, point):
return "BetaContour aMethod", self, point
def _beta_moreMethods(self, foo):
return "BetaContour moreMethods", self, foo
class Contour(BetaContour):
roboFont = Implementation("roboFont")
def _roboFont_aMethod(self, point, test):
return "Contour aMethod", self, point, test
def _beta_testing(self, someThing):
return "Contour testing", self, someThing
c = Contour()
print c.aMethod("a")
print c.roboFont.aMethod("a", "b")
print c.beta.moreMethods("bar")
print c.beta.testing("m")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment