Modshim
Languages and libraries
python import hooks
SHOW HN2025
How HN took it
5 positive, 5 neutral or asking, 1 mixed, 8 critical, out of 19 comments about the project. Thread score -0.11.
Idea: 3 for, 5 againstDocs: 1 for, 1 againstDesign: 0 for, 2 against
The thread, comment by comment
Each row is a top-level comment and its replies, in HN's order. Select a cell to open that comment on HN.
positive neutral or mixed critical about another commenter or something else the maker
What HN said
What people liked
Clean, original solution to a long-standing problem
From 1 comment
The is really awesome and an original and clean solution to a dirty old problem. Kudos.
BiteCode_dev on HN
Useful for distributing changes to third-party packages without forking
From 2 comments
I didn't really get why I'd want to actually use it (vs. just a cool demo) either, until: > means if you want to make changes to a third-party package, you don't have to take on…
OJFord on HNYeah, but the example of "*.retries(...)", in the context of "import some_login_library.Login(...)" is quite powerful! It basically looks like a "super-decorator", and I can…
ramses0 on HN
Python 3.9 to 3.14 support and good license choice noted
From 2 comments
I've tested it works from 3.9 to 3.14
joouha on HNWhat Python versions have you tested on, OP? Good license choice, by the way.
Uptrenda on HN
Objections
Import hooks add supply chain and fragility risk compared to patching
From 3 comments
For context: one of the several projects I'm working on right now is an automated extraction system for literate-code-style documentation in python. This isn't the place nor time…
nbadg on HNIf the goal is to actually package and distribute the changes via import hook, that makes the supply chain attack question particularly relevant. And it still doesn't explain why…
nbadg on HNIf you only want your own code to see the patch, then why not just wrap it? I mean if you really need super strong isolation, you can always create a copy of the library object;…
nbadg on HN
Unclear why it is needed versus wrapping or subclassing; use case not well explained
From 2 comments
If you only want your own code to see the patch, then why not just wrap it? I mean if you really need super strong isolation, you can always create a copy of the library object;…
nbadg on HNFor context: one of the several projects I'm working on right now is an automated extraction system for literate-code-style documentation in python. This isn't the place nor time…
nbadg on HN
Patches must be maintained as upstream updates, similar to an unnamed fork
From 1 comment
This feels too much like breaking the guarantee sticker of a vendor code, and if your vendor pushes updates weekly, or daily, you are stuck pushing updates to your shimmed code,…
moezd on HN
Does not handle external imports of the patched module under the original name
From 2 comments
The import limitation seems to make this not useful for me. Usually when I am monkeypatching, it's because some code I do not control has a (possibly dynamic) import of the…
o11c on HNThat's talking about internal imports (and static - as much as python supports - ones at that), not external ones. If A is my application, B is buggy, and C is some other…
o11c on HN
Requests
Explain the why and concrete use cases more thoroughly
From 2 comments
For context: one of the several projects I'm working on right now is an automated extraction system for literate-code-style documentation in python. This isn't the place nor time…
nbadg on HNIf you only want your own code to see the patch, then why not just wrap it? I mean if you really need super strong isolation, you can always create a copy of the library object;…
nbadg on HN
Support hot reload
From 1 comment
This is a nice system. I wonder if modshim can be used to or extended to do hot reload.
satya71 on HN
Mount the virtual package over the lower module for global effect
From 1 comment
It should in theory be possible to mount the new virtual package over the lower module - but I don't think works currently (I'll have to test this). Doing this would make…
joouha on HN
Questions
Is it ready to demo?
From 1 comment
Sounds super interesting. Is it ready to demo?
Uptrenda on HN
Which Python versions are supported?
From 1 comment
What Python versions have you tested on, OP? Good license choice, by the way.
Uptrenda on HN
Why not just package the monkeypatch itself?
From 1 comment
If the goal is to actually package and distribute the changes via import hook, that makes the supply chain attack question particularly relevant. And it still doesn't explain why…
nbadg on HN
Alternatives named
Wrapping or composing functions and classes
From 2 comments
If you only want your own code to see the patch, then why not just wrap it? I mean if you really need super strong isolation, you can always create a copy of the library object;…
nbadg on HNThis is interesting, and I'll try to remember to give this a go next time I'm tempted to patch something from the standard library, but... The README mentions 3 scenarios that…
afarviral on HN
Forking the library
From 2 comments
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…
procaryote on HNLet me explain what inspired me to create modshim: I've written a Jupyter client for the terminal (euporie), for which I've had to employ monkey-patching of various third-party…
joouha on HN
patchy library
From 1 comment
Also check out https://github.com/adamchainz/patchy
boxed on HN
Cargo-style dependency patching
From 1 comment
I wish a Python package manager would support patching dependencies, like e.g. Cargo allows:…
tracnar on HN