frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

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

https://github.com/joouha/modshim
41•joouha•5d ago
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.

Comments

satya71•5d ago
This is a nice system. I wonder if modshim can be used to or extended to do hot reload.
epgui•2h ago
I ported the clojure bond library over to python. It’s not quite as neat as the original, but IMO the pseudo-FP style is much more ergonomic.

https://github.com/epgui/pybond

Izkata•2h ago
Monkey-patching is altering the code at runtime, not the source code, so from the "alternative to forking and modifying" part it doesn't sound like an alternative to that.

Edit: okay Readme is clear on it and the description does make sense, the short description here just confused me.

BiteCode_dev•1h ago
The is really awesome and an original and clean solution to a dirty old problem. Kudos.
moezd•1h ago
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, which officially becomes "unnamed fork". Even for tests, let's say that they changed an input type, I don't see an improvement in my workflow: I still need to update my "unnamed fork". At least with a fork I get to see the whole git history, including my contributions, and testing with monkey patching helps me create clear setUp and tearDown steps.

When you have a scalpel, you give it to operating doctors during the operation, not to 5 year olds on the street.

o11c•1h ago
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 "buggy" module under another name, so I need to make my changes visible under the original name.

If I control all the imports I can usually subclass things myself just fine.

theptip•55m ago
> Because our enhanced Session class now enables retries by default, we don't even need to instantiate it directly. modshim's AST rewriting ensures that internal references within the requests module are updated. This means convenience functions like requests.get() will automatically use our enhanced Session class

This seems to explicitly handle the case you are interested in - automatically updating library-internal references to the lower to instead use the upper?

o11c•47m ago
That'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 library, consider:

  # A.py
  monkeypatch_B()
  import C

  # C.py
  B = __import__('B')

  # B.py
  bugs()

Evaluating the Infinity Cache in AMD Strix Halo

https://chipsandcheese.com/p/evaluating-the-infinity-cache-in
39•zdw•2h ago•16 comments

If you'd built a "tool" that stupid, why would you advertise the fact?

https://svpow.com/2025/10/13/if-youd-built-a-tool-that-stupid-why-would-you-advertise-the-fact/
44•surprisetalk•1w ago•6 comments

French ex-president Sarkozy begins jail sentence

https://www.bbc.com/news/articles/cvgkm2j0xelo
18•begueradj•42m ago•3 comments

rlsw – Raylib software OpenGL renderer in less than 5k LOC

https://github.com/raysan5/raylib/blob/master/src/external/rlsw.h
159•fschuett•9h ago•35 comments

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

https://github.com/joouha/modshim
42•joouha•5d ago•9 comments

LLMs can get "brain rot"

https://llm-brain-rot.github.io/
345•tamnd•16h ago•198 comments

Power over Ethernet (PoE) basics and beyond

https://www.edn.com/poe-basics-and-beyond-what-every-engineer-should-know/
141•voxadam•5d ago•98 comments

Replacing a $3000/mo Heroku bill with a $55/mo server

https://disco.cloud/blog/how-idealistorg-replaced-a-3000mo-heroku-bill-with-a-55-server/
555•jryio•10h ago•387 comments

OpenBSD 7.8

https://cdn.openbsd.org/pub/OpenBSD/7.8/ANNOUNCEMENT
139•paulnpace•4h ago•32 comments

Wikipedia says traffic is falling due to AI search summaries and social video

https://techcrunch.com/2025/10/18/wikipedia-says-traffic-is-falling-due-to-ai-search-summaries-an...
360•gmays•1d ago•319 comments

Ask HN: Our AWS account got compromised after their outage

256•kinj28•14h ago•63 comments

Neural audio codecs: how to get audio into LLMs

https://kyutai.org/next/codec-explainer
352•karimf•17h ago•104 comments

The Hidden Engineering of Niagara Falls

https://practical.engineering/blog/2025/10/21/the-hidden-engineering-of-niagara-falls
91•chmaynard•7h ago•2 comments

NASA chief suggests SpaceX may be booted from moon mission

https://www.cnn.com/2025/10/20/science/nasa-spacex-moon-landing-contract-sean-duffy
274•voxleone•17h ago•789 comments

Mathematicians have found a hidden 'reset button' for undoing rotation

https://www.newscientist.com/article/2499647-mathematicians-have-found-a-hidden-reset-button-for-...
122•mikhael•5d ago•82 comments

ChatGPT Atlas

https://chatgpt.com/atlas
630•easton•13h ago•591 comments

Getting DeepSeek-OCR working on an Nvidia Spark via brute force with Claude Code

https://simonwillison.net/2025/Oct/20/deepseek-ocr-claude-code/
150•simonw•1d ago•31 comments

Erowid - Documenting the Complex Relationship Between Humans and Psychoactives

https://www.erowid.org
58•slow_typist•10h ago•3 comments

Build your own database

https://www.nan.fyi/database
452•nansdotio•14h ago•68 comments

Researchers complete first human trial on viability of enteral ventilation

https://newatlas.com/disease/butt-breathing-ignobel-prize/
38•mustaphah•11h ago•44 comments

What do we do if SETI is successful?

https://www.universetoday.com/articles/what-do-we-do-if-seti-is-successful
140•leephillips•1d ago•239 comments

Minds, brains, and programs (1980) [pdf]

https://home.csulb.edu/~cwallis/382/readings/482/searle.minds.brains.programs.bbs.1980.pdf
66•measurablefunc•1w ago•24 comments

The death of thread per core

https://buttondown.com/jaffray/archive/the-death-of-thread-per-core/
104•ibobev•1d ago•39 comments

Understanding conflict resolution and avoidance in PostgreSQL: a complete guide

https://www.pgedge.com/blog/living-on-the-edge
32•birdculture•1w ago•6 comments

Drawing Text Isn't Simple: Benchmarking Console vs. Graphical Rendering

https://cv.co.hu/csabi/drawing-text-performance-graphical-vs-console.html
9•todsacerdoti•1w ago•9 comments

KDE Connect: Enabling communication between all your devices

https://community.kde.org/KDEConnect
409•snthd•1w ago•168 comments

Foreign hackers breached a US nuclear weapons plant via SharePoint flaws

https://www.csoonline.com/article/4074962/foreign-hackers-breached-a-us-nuclear-weapons-plant-via...
361•zdw•14h ago•256 comments

Doomsday scoreboard

https://doomsday.march1studios.com/
198•diymaker•10h ago•96 comments

Show HN: Katakate – Dozens of VMs per node for safe code exec

https://github.com/Katakate/k7
101•gbxk•15h ago•37 comments

Show HN: AutoLearn Skills for self-improving agents

https://www.autolearn.dev
15•toobulkeh•3h ago•8 comments