Skip to main content

Monkey patching utilities for classes

Project description

class-interference

Monkey patching utilities for classes.

Installation

pip install class-interference

Usage example

from class_interference import Extension, inject, apply_extensions


class LibraryClass:
    def library_method(self, *args, **kwargs):
        return None


class LibraryClassExtension(LibraryClass, Extension):
    @inject
    def library_method(self, *args, **kwargs):
        original_value = self.super_ext.library_method(*args, **kwargs)
        if original_value is None:
            raise ValueError
        return original_value


apply_extensions(LibraryClassExtension)

if __name__ == "__main__":
    library_class_instance = LibraryClass()
    library_class_instance.library_method()  # raises ValueError

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

class_interference-1.1.1.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

class_interference-1.1.1-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

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