Skip to main content

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 orig.imag

Links

Github

PyPi

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fishhook-0.2.8.post10.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fishhook-0.2.8.post10-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file fishhook-0.2.8.post10.tar.gz.

File metadata

  • Download URL: fishhook-0.2.8.post10.tar.gz
  • Upload date:
  • Size: 8.8 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

Hashes for fishhook-0.2.8.post10.tar.gz
Algorithm Hash digest
SHA256 ca74f84fd380c3f3ead47405405ef355343a9ebacf4f5d14043576c8294359b7
MD5 a043061a8a58ea7e20008b1b8911cf68
BLAKE2b-256 a76ca9f5c93f5074c704ff7d3ad8902f9cc531e87d02a5388edf38df63ed5b80

See more details on using hashes here.

File details

Details for the file fishhook-0.2.8.post10-py3-none-any.whl.

File metadata

  • Download URL: fishhook-0.2.8.post10-py3-none-any.whl
  • Upload date:
  • Size: 13.5 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

Hashes for fishhook-0.2.8.post10-py3-none-any.whl
Algorithm Hash digest
SHA256 890b1d8b618bd49fda13e3aa851acbfa35cbc013439327cbd2bf9be3cb0ff7f7
MD5 4669ef7c114db2713942b981b65eb1d9
BLAKE2b-256 c831470706d8417d5da83234b839d68a91dc1e853dd3c838db2868b9bc446d33

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page