mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-14 20:57:59 +00:00
Fixes #144976 Using appoach ① `IO[bytes]`, but could also try with a protocol. ## Notes: - moved `torch.serialization.FILE_LIKE` to `torch.types.FileLike` - Use `FileLike` annotation where it makes sense - made sure those functions also support `os.PathLike` - Replaced `isinstance(x, io.BytesIO)` with `isinstance(x, (io.IOBase, IO))` where appropriate. - Replaced `BinaryIO` with `IO[bytes]` (the two ABCs are almost identical, the only difference is that `BinaryIO` allows `bytearray` input to `write`, whereas `IO[bytes]` only `bytes`) - needed to make `torch.serialization._opener` generic to avoid LSP violations. - skipped `torch/onnx/verification` for now (functions use `BytesIO.getvalue` which is not part of the `IO[bytes]` ABC, but it kind of seems that this is redundant, as e.g. `onnx.load` supports `str | PathLike[str] | IO[bytes]` directly... Pull Request resolved: https://github.com/pytorch/pytorch/pull/144994 Approved by: https://github.com/ezyang, https://github.com/Skylion007 |
||
|---|---|---|
| .. | ||
| analyze | ||
| __init__.py | ||
| _digraph.py | ||
| _directory_reader.py | ||
| _importlib.py | ||
| _mangling.py | ||
| _mock.py | ||
| _package_pickler.py | ||
| _package_unpickler.py | ||
| _stdlib.py | ||
| file_structure_representation.py | ||
| find_file_dependencies.py | ||
| glob_group.py | ||
| importer.py | ||
| mangling.md | ||
| package_exporter.py | ||
| package_importer.py | ||