Inspect.getmodule returns None

If I open my interpreter 3.8, 3.9, 3.10 and enter this

print(inspect.getmodule(inspect.currentframe()))

It always prints None. Under some other circumstances which I did not figure out yet, it may (correctly) return

sys.modules["__main__"].

Can somebody please explain what is the correct behavior?

I think I nailed it down to sys.modules["__main__"].__file__ which sometimes exists and equal to <stdin> and sometimes not.