mirror of
https://github.com/vale981/ray
synced 2025-03-06 02:21:39 -05:00
[air] Raise error on path-like access for Checkpoints (#26970)
Calling e.g. `os.path.exists(checkpoint)` currently raises an TypeError, but we should make it more explicit and guide users towards the correct API. Signed-off-by: Kai Fricke <kai@anyscale.com>
This commit is contained in:
parent
5315f1e643
commit
df217d15e0
2 changed files with 12 additions and 0 deletions
|
@ -627,6 +627,12 @@ class Checkpoint:
|
|||
def __setstate__(self, state):
|
||||
self.__dict__.update(state)
|
||||
|
||||
def __fspath__(self):
|
||||
raise TypeError(
|
||||
"You cannot use `air.Checkpoint` objects directly as paths. "
|
||||
"Use `Checkpoint.to_directory()` or `Checkpoint.as_directory()` instead."
|
||||
)
|
||||
|
||||
def get_preprocessor(self) -> Optional["Preprocessor"]:
|
||||
"""Return the saved preprocessor, if one exists."""
|
||||
|
||||
|
|
|
@ -544,6 +544,12 @@ class PreprocessorCheckpointTest(unittest.TestCase):
|
|||
preprocessor = checkpoint.get_preprocessor()
|
||||
assert preprocessor.multiplier == 1
|
||||
|
||||
def testAttrPath(self):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
checkpoint = Checkpoint.from_directory(tmpdir)
|
||||
with self.assertRaises(TypeError):
|
||||
os.path.exists(checkpoint)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import pytest
|
||||
|
|
Loading…
Add table
Reference in a new issue