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:
if inspect.isclass(obj):
try:
obj.what = whatablefunc
except:
from forbiddenfruit import curse
curse(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.
Sometimes it can be useful to add a
whatmethod 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
whatfunctions to thewhatabledecorator (in any case introspection won't work with these kind of objects). These few lines inwhatablemade 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.