Inspect.getmodule returns None

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


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


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.