I have some code which I would like to pass instances or classes interchangeably. All I will do in that code is to call a method that I expect both classes and instances to have (the method go() in the example below).
Unfortunately, I can’t create a classmethod with the same name of a regular method… See example below. I initially expected the second call to produce an a instead of a b.
Any advice on how to achieve this?
Type "help", "copyright", "credits" or "license" for more information.
>>> class A(object):
... def go(self):
... print "a"
... @classmethod
... def go(cls):
... print "b"
...
>>> a=A()
>>> a.go()
b
>>> A.go()
b
Consider reusing the
classinstancemethoddecorator from formencode.https://bitbucket.org/formencode/official-formencode/src/06d52c5b33c9/formencode/declarative.py