mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
Adds suppressions to pyrefly will typecheck clean: https://github.com/pytorch/pytorch/issues/163283 Almost there! Test plan: dmypy restart && python3 scripts/lintrunner.py -a pyrefly check step 1: delete lines in the pyrefly.toml file from the project-excludes field step 2: run pyrefly check step 3: add suppressions, clean up unused suppressions before: https://gist.github.com/maggiemoss/4b3bf2037014e116bc00706a16aef199 after: INFO 0 errors (6,884 ignored) Pull Request resolved: https://github.com/pytorch/pytorch/pull/164913 Approved by: https://github.com/oulgen
38 lines
1018 B
Python
38 lines
1018 B
Python
"""
|
|
Python polyfills for os
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from typing import AnyStr
|
|
|
|
from ..decorators import substitute_in_graph
|
|
|
|
|
|
__all__ = ["fspath"]
|
|
|
|
|
|
# Copied from os.py in the standard library
|
|
@substitute_in_graph(os.fspath, can_constant_fold_through=True)
|
|
def fspath(path: AnyStr | os.PathLike[AnyStr]) -> AnyStr:
|
|
if isinstance(path, (str, bytes)):
|
|
# pyrefly: ignore # bad-return
|
|
return path
|
|
|
|
path_type = type(path)
|
|
try:
|
|
path_repr = path_type.__fspath__(path) # type: ignore[arg-type]
|
|
except AttributeError:
|
|
if hasattr(path_type, "__fspath__"):
|
|
raise
|
|
raise TypeError(
|
|
f"expected str, bytes or os.PathLike object, not {path_type.__name__}",
|
|
) from None
|
|
if isinstance(path_repr, (str, bytes)):
|
|
return path_repr # type: ignore[return-value]
|
|
raise TypeError(
|
|
f"expected {path_type.__name__}.__fspath__() to return str or bytes, "
|
|
f"not {type(path_repr).__name__}",
|
|
)
|