You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes it can be useful to add a what method to an extension type. I would recommend in these cases to be clean and create a whatable function/class that delegates the work to the function in C-land.
However, it might be useful to allow monkey-patching extension types. Some info here and here.
forbiddenfruit is a small tool to nastily monkey-patch any extension type (including builtins). It is released in pypi GPL licensed, although whatami can use it under the MIT license. I have been playing with it and works great, so it can be a neat addition together with the ability to specify custom what functions to the whatable decorator (in any case introspection won't work with these kind of objects). These few lines in whatable made the trick:
ifinspect.isclass(obj):
try:
obj.what=whatablefuncexcept:
fromforbiddenfruitimportcursecurse(obj, 'what', whatablefunc)
print('WARNING, patched builtin/extension type %s'%type(obj))
# This will anyway fail for extension types # (can we make forbiddenfruit work with instances?)
Also add a like like this to optional dependencies in setup.py:
'ubermonkey': ('forbiddenfruit',),
Note: the comments on the forbiddenfruit issue tracker are an interesting read.
The text was updated successfully, but these errors were encountered:
It does not seem to be a good idea. Testing at 2b29f5a showed very unstable interpreter and random crashes after enacting forbiddenfruit. Will assess alternative ways (e.g. dynamically create mixins inheriting from extension types and adding the what method).
sdvillal
changed the title
Use forbiddenfruit to monkey patch extension types
Monkey patch / decorate extension types
Aug 13, 2015
Sometimes it can be useful to add a
what
method to an extension type. I would recommend in these cases to be clean and create a whatable function/class that delegates the work to the function in C-land.However, it might be useful to allow monkey-patching extension types. Some info here and here.
forbiddenfruit is a small tool to nastily monkey-patch any extension type (including builtins). It is released in pypi GPL licensed, although whatami can use it under the MIT license. I have been playing with it and works great, so it can be a neat addition together with the ability to specify custom
what
functions to thewhatable
decorator (in any case introspection won't work with these kind of objects). These few lines inwhatable
made the trick:Also add a like like this to optional dependencies in setup.py:
Note: the comments on the forbiddenfruit issue tracker are an interesting read.
The text was updated successfully, but these errors were encountered: