{"by":"joouha","descendants":30,"id":45604013,"kids":[45666046,45665197,45667582,45665540,45664756,45664849,45665116,45664919,45607185,45671941,45667329,45665664,45665661,45668272],"score":109,"text":"I&#x27;ve invented a new alternative to forking &#x2F; vendoring &#x2F; monkey-patching packages in Python.<p>It&#x27;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).<p>It works by rewriting imports using AST transformations, then running both the lower and upper module&#x27;s code in the new Python module.<p>This prevents polluting the global namespace when monkey-patching, and means if you want to make changes to a third-party package, you don&#x27;t have to take on the maintenance burden of forking, you can package and distribute just your changes.","time":1760613476,"title":"Show HN: Modshim – A new alternative to monkey-patching in Python","type":"story","url":"https://github.com/joouha/modshim"}