Skip to content

Instantly share code, notes, and snippets.

@pmuller
Created June 29, 2018 05:23
Show Gist options
  • Save pmuller/bd1ac430d090c94c37b37e4f48db3974 to your computer and use it in GitHub Desktop.
Save pmuller/bd1ac430d090c94c37b37e4f48db3974 to your computer and use it in GitHub Desktop.
>>> class Descriptor:
... def __get__(self, instance, owner):
... print('__get__', instance, owner)
... print('called on a', 'class' if instance is None else 'instance')
...
>>> class Class:
... foo = Descriptor()
...
>>> Class.foo
__get__ None <class '__main__.Class'>
called on a class
>>> Class().foo
__get__ <__main__.Class object at 0x7f95551cf4e0> <class '__main__.Class'>
called on a instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment