-
-
Save keflavich/5806078 to your computer and use it in GitHub Desktop.
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
import functools | |
class class_or_instance(object): | |
def __init__(self, fn): | |
self.fn = fn | |
def __get__(self, obj, cls): | |
if obj is not None: | |
return lambda *args, **kwds: self.fn(obj, *args, **kwds) | |
else: | |
return lambda *args, **kwds: self.fn(cls, *args, **kwds) | |
class UKIDSS(object): | |
@class_or_instance | |
def query(self): | |
if self is UKIDSS: | |
print("Calling query as class method") | |
else: | |
print("Calling query as instance method") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment