[package] fix corner case in PacakgeImporter.whichmodule (#57651)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57651
We've gone back and forth on whether to emulate the `sys.modules` lookup
behavior in our own `whichmodule`, the provided test is a concrete case
for doing so.
An additional minor cleanup is to make the type of `self.modules` in
importers `Dict[str, ModuleType]`. Modules could only be None in the
dictionary in older versions of the import system
Test Plan: Imported from OSS
Reviewed By: SplitInfinity
Differential Revision: D28226536
Pulled By: suo
fbshipit-source-id: c2e6da91651ddaa4fbf7171555df9e5cbe1060fd