Skip to content

Instantly share code, notes, and snippets.

@studiotomi
Created July 14, 2015 22:33
Show Gist options
  • Save studiotomi/18cf6c91e80da680d5a3 to your computer and use it in GitHub Desktop.
Save studiotomi/18cf6c91e80da680d5a3 to your computer and use it in GitHub Desktop.
Find what base class an attributes is coming from in Python
def find_attribute_class(model, attribute):
"""
If the attribute is found, it returns an array of places the attribute is defined.
The array is ordered by priority, the first element being the one that is called.
If not found, returns an empty array.
"""
return [m for m in model.mro() if attribute in m.__dict__]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment