This is not true. You changed the signature of the function to include a new parameter.
> Let me tell you your mind is going to be blown once you learn about Monads.
You know about monads and you do this type of injection hack in your example? You realize Haskells type system exactly segregates things the way ChatGPT did it right? The IO monad prevents you from injecting prints into your pure logic, you have to use bind to segregate things from being polluted with the IO monad. Literally haskells type system forces you to code for unit test ability AS A type check; meaning if your code isn't unit testable, it's a Type Error.
>A mutable object is functionally identical to a return value if you control the initial state and lifetime of the object. Like you can do in a unit test.
Yeah it is, but you had to change the function signature to get it. Either a mutable input value or a return value. Pick one. You chose the former. Your dependency injection example IS a valid unit test but it is completely untrue that you did not change the semantics of the function, you HAD to change it, you had no choice.
Also lifetimes don't matter in python too much as it is garbage collected. You nor does any other scoped owner control the lifetime of an object in python. The garbage collector controls the lifetime via reference counting... but this is off topic.
A mutable object is functionally identical to a return value if you control the initial state and lifetime of the object. Like you can do in a unit test.
And as I demonstrated in my other comment I 100% retained the semantic structure of the function whilst making it 100% unit testable.