From 9d26f8f4fe1654bfe7e2f631f892a8cf08caf050 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Mon, 17 Apr 2023 16:59:40 -0700 Subject: [PATCH] Use os.fspath on Path (#15530) ### Description Use os.fspath instead of str() on a path object. ### Motivation and Context I learned today that os.fspath is the right way to go: https://github.com/charliermarsh/ruff/issues/3675#issuecomment-1494975508 --- onnxruntime/python/onnxruntime_inference_collection.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/onnxruntime/python/onnxruntime_inference_collection.py b/onnxruntime/python/onnxruntime_inference_collection.py index d9fc44f5b8..b19346f99a 100644 --- a/onnxruntime/python/onnxruntime_inference_collection.py +++ b/onnxruntime/python/onnxruntime_inference_collection.py @@ -359,11 +359,8 @@ class InferenceSession(Session): """ super().__init__() - if isinstance(path_or_bytes, str): - self._model_path = path_or_bytes - self._model_bytes = None - elif isinstance(path_or_bytes, os.PathLike): - self._model_path = str(path_or_bytes) + if isinstance(path_or_bytes, (str, os.PathLike)): + self._model_path = os.fspath(path_or_bytes) self._model_bytes = None elif isinstance(path_or_bytes, bytes): self._model_path = None