mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[Dynamo][Better Engineering] Type coverage for torch/_dynamo/utils.py
(#159580)
As part of better engineering effort, we would like to improve out type support to improve dev experience in dynamo This PR adds strict typing support to `torch/_dynamo/utils.py` Running ``` mypy torch/_dynamo/utils.py --linecount-report /tmp/coverage_log ``` | -------- | Lines Annotated | Lines Total | % lines covered | Funcs Annotated | Funcs Total | % funcs covered | | -------- | ------- | -------- | ------- | ------- | ------- | ------- | | Main | 2163 | 4792 | 45.14% | 121 | 268 | 45.15% | | This PR | 4818 | 4818 | 100.00% | 268 | 268 | 100.00% | | Delta | +2655 | +26 | +54.84% | +147 | 0 | +54.85% | Pull Request resolved: https://github.com/pytorch/pytorch/pull/159580 Approved by: https://github.com/williamwen42
This commit is contained in:
committed by
PyTorch MergeBot
parent
510e8b4ae0
commit
a7f3bdf550
@ -15,8 +15,9 @@ and recreate specific program states.
|
|||||||
|
|
||||||
import dataclasses
|
import dataclasses
|
||||||
from dataclasses import field
|
from dataclasses import field
|
||||||
|
from io import BufferedReader, BufferedWriter
|
||||||
from types import CellType, CodeType, ModuleType
|
from types import CellType, CodeType, ModuleType
|
||||||
from typing import Any, IO
|
from typing import Any, IO, Union
|
||||||
from typing_extensions import Self
|
from typing_extensions import Self
|
||||||
|
|
||||||
from torch.utils._import_utils import import_dill
|
from torch.utils._import_utils import import_dill
|
||||||
@ -51,12 +52,12 @@ class ExecutionRecord:
|
|||||||
builtins: dict[str, Any] = field(default_factory=dict)
|
builtins: dict[str, Any] = field(default_factory=dict)
|
||||||
code_options: dict[str, Any] = field(default_factory=dict)
|
code_options: dict[str, Any] = field(default_factory=dict)
|
||||||
|
|
||||||
def dump(self, f: IO[str]) -> None:
|
def dump(self, f: Union[IO[str], BufferedWriter]) -> None:
|
||||||
assert dill is not None, "replay_record requires `pip install dill`"
|
assert dill is not None, "replay_record requires `pip install dill`"
|
||||||
dill.dump(self, f)
|
dill.dump(self, f)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, f: IO[bytes]) -> Self:
|
def load(cls, f: Union[IO[bytes], BufferedReader]) -> Self:
|
||||||
assert dill is not None, "replay_record requires `pip install dill`"
|
assert dill is not None, "replay_record requires `pip install dill`"
|
||||||
return dill.load(f)
|
return dill.load(f)
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user