Re:Never run ‘python’ in your downloads folder
by Izkata on Sunday August 23, 2020 @06:26PM
(#24255828)
Unless something has changed or there's a detail involving builtins I'm not aware of, I don't think this would work, for the same reason as the most common pitfall when mocking functions in python: You have to replace it where it's used, not where it's defined. To do that on a module, you have to first import that module - and then all the imports at the top of it would've already run.
[ Parent
| on HN ]
Re:Never run ‘python’ in your downloads folder
by yzmtf2008 on Sunday August 23, 2020 @06:55PM
(#24255983)
> To do that on a module, you have to first import that module - and then all the imports at the top of it would've already run.
Why not just replace the `__import__` function at program startup, when you haven't imported anything? Monkey patching `__import__` at any other time seems like a bad idea.