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.9.tar.gz (9.1 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.9-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file fishhook-0.2.9.tar.gz.

File metadata

  • Download URL: fishhook-0.2.9.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for fishhook-0.2.9.tar.gz
Algorithm Hash digest
SHA256 98093d817a77fab34dec76531853f2c01a3b74fb953c63e4e3dc800b2383dbed
MD5 8cc08ccaf56725704011c3b096912a1b
BLAKE2b-256 5a7c45f13560d7bb7b5a595ed20fd4f42fc306000d08bdc889f0ca741038888e

See more details on using hashes here.

File details

Details for the file fishhook-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: fishhook-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for fishhook-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 858ea54119dab65cc08183a2323bda3fd2c23d9eda21f1433ac43fd40d827870
MD5 5a3c4277ed8f3cbc02cb5972d5bef394
BLAKE2b-256 3535c1622f9bd36aaa2ab2041d9c4db5d4a37e3cce2e8721303cc2d44883bc8c

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