Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jpablo/python-extension-methods
Metaclass for easily extending classes (monkeypatching)
https://github.com/jpablo/python-extension-methods
Last synced: 10 days ago
JSON representation
Metaclass for easily extending classes (monkeypatching)
- Host: GitHub
- URL: https://github.com/jpablo/python-extension-methods
- Owner: jpablo
- Created: 2011-08-14T15:14:19.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-08-14T15:35:42.000Z (over 13 years ago)
- Last Synced: 2024-11-14T00:52:05.911Z (about 2 months ago)
- Homepage:
- Size: 93.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ExtendClass
A metaclass that allows to extend a class with methods from another.
## Example
```python
from django.contrib.auth.models import Userclass UserExtension(object):
__metaclass__ = ExtendClass(User)
@property
def profile(self):
return self.get_profile()def in_group(self, name):
return self.groups.filter(name=name).count() > 0# >>> u = User.objects.all()[0]
# >>> assert u.profile == u.get_profile()
# >>> assert u.in_group("crazy_group") == False
```## TODO
The real reason for this metaclass is to detect if we are overriding something.
1. Warn if something is being overriden
2. Optionally force override
3. Friendly interface, something like "class UserExtension(User,Extension): ... "