"import wat" would be great, but Python has some restrictions about modules not being callable. That's why I ended up with longer `from wat import wat`. Not sure but maybe this would be more convenient `import wat; wat.wat / object`
Edit: Oh, you don't mean in the importing module's globals, you mean `sys.modules`. Yeah that works!
why do you say it's wonky? it's just
sys.modules[__name__] = wat
According to the official python documentation [0] of sys.modules:> This is a dictionary that maps module names to modules which have already been loaded. This can be manipulated to force reloading of modules and other tricks.
Thus, the modules dictionary is being used as intended, and it has the desired effect. Nothing wonky about that.
Of course, a __call__ method would be better because you could still keep the other functions inside the module. But for a single-function import like "wat" it seems quite natural and sane.
import sys
def wat(): print("wat")
def bar(): print("bar")
wat.wat = wat
wat.bar = bar
sys.modules[__name__] = wat
... >>> import wat
>>> wat()
wat
>>> from wat import bar
>>> bar()
bar
Edit: I think a better way would be to instead add __call__ to the current module somehow though.