←back to thread

107 points joouha | 1 comments | | HN request time: 0.208s | source

I've invented a new alternative to forking / vendoring / monkey-patching packages in Python.

It's a bit like OverlayFS for Python modules - it allows you write modifications for a target module (lower) in a new module (upper), and have these combined in a new virtual module (mount).

It works by rewriting imports using AST transformations, then running both the lower and upper module's code in the new Python module.

This prevents polluting the global namespace when monkey-patching, and means if you want to make changes to a third-party package, you don't have to take on the maintenance burden of forking, you can package and distribute just your changes.

1. procaryote ◴[] No.45665664[source]
Of these:

> * Fix bugs in third-party libraries without forking

> * Modify the behavior of existing functions

> * Add new features or options to existing classes

> * Test alternative implementations in an isolated way

only the last sounds close to something you might actually want to do, and then only as a throwaway thing

If you want to change a library, fork it. If you want to change the behavior of existing functions, don't or at least fork first. If you want to add new features to a class, write a new class, or again, at least fork first