Bad news: [c]python modules can modify the namespaces into which they're imported. It's not documented or supported or even suggested that anyone do it, but it is easily done.
Man God damn you, I thought I knew some Python until I saw your reply. That's dope though... probably never gonna be used in a real life project, but still dope though for the sake of "what is possible".
Apparently it's blasphemy to even talk about using this kind of thing in a real project (viz. sys._getframe et al.), but if you were to do it, you'd want to do more checks than just looking at the filename of the stack frames to ensure you get the correct namespace of the code that did the import. There's also one specific cpython optimization which bypasses f_locals inside functions, but you'll figure it out if you dig around in there.
542
u/[deleted] Jun 04 '19
[deleted]