←back to thread

107 points joouha | 1 comments | | HN request time: 0.321s | 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. yincong0822 ◴[] No.45668272[source]
That’s a really cool idea — kind of like OverlayFS but for Python modules. I like how it lets you layer changes on top of existing packages without having to fork or monkey-patch them directly.

The big win here is that it keeps things clean and maintainable — you only ship your changes instead of managing a full fork, and you don’t mess up the global namespace. It also makes experimenting with tweaks a lot easier.

The tricky parts might be keeping import behavior consistent and making sure debugging still works nicely since AST rewriting can sometimes make stack traces a bit messy.

Overall, it’s a clever middle ground between monkey-patching and forking — really nice concept.