https://github.com/jpablo/python-extension-methods
Metaclass for easily extending classes (monkeypatching)
https://github.com/jpablo/python-extension-methods
Last synced: 5 months 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 (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2011-08-14T15:35:42.000Z (almost 15 years ago)
- Last Synced: 2025-05-16T04:08:01.797Z (about 1 year ago)
- Homepage:
- Size: 93.8 KB
- Stars: 1
- Watchers: 1
- 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 User
class 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): ... "