MHN

Show HN: Modshim – A new alternative to monkey-patching in Python

109 points by joouha·410 days ago·github.com·Show in HN

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.

Add a comment on Hacker News →
1 of 30 comments
  1. The is really awesome and an original and clean solution to a dirty old problem. Kudos.