Allows for runtime hooking of static class functions
Project description
Fishhook
This module allows for swapping out the slot pointers contained in static classes with the generic slot pointers used by python for heap classes. This allows for assigning arbitrary python functions to static class dunders using hook and hook_cls and for applying new functionality to previously unused dunders. A hooked static dunder can be restored to original functionality using the unhook function
it is possible to hook descriptors using hook.property, and an example can be seen below
Calling original methods
orig(self, *args, **kwargs) is a special function that looks up the original implementation of a hooked dunder in the methods cache. It will only work properly when used inside a hooked method where an original implementation existed
hooking single methods
@hook(int)
def __add__(self, other):
...
return orig(self, other)
hooking multiple methods
@hook_cls(int)
class int_hook:
attr = ...
def __add__(self, other):
...
hooking descriptors
@hook.property(int)
def imag(self):
...
return imag.orig
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fishhook-0.2.3.tar.gz.
File metadata
- Download URL: fishhook-0.2.3.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f17f40cca0a3e28735ba08189b6ddd5886302e74a91bed1249230275eeea1df9
|
|
| MD5 |
ba507cc7715c34fbabc021ff18069d58
|
|
| BLAKE2b-256 |
26b8772e890cacb26cc9c74cf36f1b9744aad842955af78ce7c1088e1209c249
|
File details
Details for the file fishhook-0.2.3-py3-none-any.whl.
File metadata
- Download URL: fishhook-0.2.3-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c3fe5ca116cb08ad7c38cb55227adf2d3f08d37544fdc7762fce37846e7aa98
|
|
| MD5 |
77dc086353b78edf1546c1713a62f6cf
|
|
| BLAKE2b-256 |
3efe6301cc16ffb26a45f5b66d8cfbe4e1abf3dc492734e237b612e962454f2f
|