Fix assertion error (PY-13378).
extract common method to ModuleUtil