mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Fixes https://github.com/pytorch/pytorch/issues/75927. Had to fix some bugs and add some ignores. To check if clean: ``` lintrunner --paths-cmd='git grep -Il .' --take MYPY,MYPYSTRICT ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/76753 Approved by: https://github.com/malfet
14 lines
379 B
Python
14 lines
379 B
Python
from importlib.abc import Loader
|
|
from types import ModuleType
|
|
from typing import cast
|
|
|
|
|
|
def import_module(name: str, path: str) -> ModuleType:
|
|
import importlib.util
|
|
|
|
spec = importlib.util.spec_from_file_location(name, path)
|
|
assert spec is not None
|
|
module = importlib.util.module_from_spec(spec)
|
|
cast(Loader, spec.loader).exec_module(module)
|
|
return module
|