From 325aa2c1a30ad16f02eab9772c03a2890c46eb1d Mon Sep 17 00:00:00 2001 From: Alicja Miloszewska Date: Tue, 27 Jan 2026 18:30:38 +0100 Subject: [PATCH 1/3] Support pathlib.Path as ov::Any --- src/bindings/python/src/pyopenvino/utils/utils.cpp | 6 ++++-- src/bindings/python/tests/test_runtime/test_core.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bindings/python/src/pyopenvino/utils/utils.cpp b/src/bindings/python/src/pyopenvino/utils/utils.cpp index ed720e77e80afa..2cd6068d223b41 100644 --- a/src/bindings/python/src/pyopenvino/utils/utils.cpp +++ b/src/bindings/python/src/pyopenvino/utils/utils.cpp @@ -453,8 +453,10 @@ std::tuple tuple_from_py_tuple(const py::tuple& py_tuple) { ov::Any py_object_to_any(const py::object& py_obj) { // Python types py::object float_32_type = py::module_::import("numpy").attr("float32"); - if (py::isinstance(py_obj)) { - return py_obj.cast(); + py::object Path = py::module_::import("pathlib").attr("Path"); + if (py::isinstance(py_obj) || py::isinstance(py_obj, Path)) { + py::bytes utf8_bytes = py::str(py_obj).attr("encode")("utf-8"); + return std::string(utf8_bytes); } else if (py::isinstance(py_obj)) { return py_obj.cast(); } else if (py::isinstance(py_obj)) { diff --git a/src/bindings/python/tests/test_runtime/test_core.py b/src/bindings/python/tests/test_runtime/test_core.py index fc0e994eea4ed6..8e8fef9672b3c9 100644 --- a/src/bindings/python/tests/test_runtime/test_core.py +++ b/src/bindings/python/tests/test_runtime/test_core.py @@ -153,7 +153,7 @@ def test_read_model_from_ir_with_user_config(request, tmp_path): core_cache_dir = core.get_property("CACHE_DIR") cache_path = tmp_path / Path("cache") - model = core.read_model(xml_path, bin_path, config={"CACHE_DIR": f"{cache_path}"}) + model = core.read_model(xml_path, bin_path, config={"CACHE_DIR": cache_path}) assert isinstance(model, Model) assert core_cache_dir == core.get_property("CACHE_DIR") @@ -209,7 +209,7 @@ def test_read_model_as_path_with_user_config(request, tmp_path): core_cache_dir = core.get_property("CACHE_DIR") cache_path = tmp_path / Path("cache_as_path") - model = core.read_model(Path(xml_path), Path(bin_path), config={"CACHE_DIR": f"{cache_path}"}) + model = core.read_model(Path(xml_path), Path(bin_path), config={"CACHE_DIR": cache_path}) assert isinstance(model, Model) assert core_cache_dir == core.get_property("CACHE_DIR") From dfa2a665fad53c1c94216d9169595e709fa4f178 Mon Sep 17 00:00:00 2001 From: Alicja Miloszewska Date: Wed, 28 Jan 2026 11:42:29 +0100 Subject: [PATCH 2/3] remove encoding --- src/bindings/python/src/pyopenvino/utils/utils.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bindings/python/src/pyopenvino/utils/utils.cpp b/src/bindings/python/src/pyopenvino/utils/utils.cpp index 2cd6068d223b41..dc795a9702ead3 100644 --- a/src/bindings/python/src/pyopenvino/utils/utils.cpp +++ b/src/bindings/python/src/pyopenvino/utils/utils.cpp @@ -455,8 +455,7 @@ ov::Any py_object_to_any(const py::object& py_obj) { py::object float_32_type = py::module_::import("numpy").attr("float32"); py::object Path = py::module_::import("pathlib").attr("Path"); if (py::isinstance(py_obj) || py::isinstance(py_obj, Path)) { - py::bytes utf8_bytes = py::str(py_obj).attr("encode")("utf-8"); - return std::string(utf8_bytes); + return py::str(py_obj).cast(); } else if (py::isinstance(py_obj)) { return py_obj.cast(); } else if (py::isinstance(py_obj)) { From 0efb762d28ec070a9dd108c1e3198b75e2b754b1 Mon Sep 17 00:00:00 2001 From: Alicja Miloszewska Date: Tue, 3 Feb 2026 11:21:14 +0100 Subject: [PATCH 3/3] Update tests --- src/bindings/python/tests/test_runtime/test_core.py | 2 +- src/bindings/python/tests/test_runtime/test_properties.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bindings/python/tests/test_runtime/test_core.py b/src/bindings/python/tests/test_runtime/test_core.py index 8e8fef9672b3c9..eb0c88f247e31b 100644 --- a/src/bindings/python/tests/test_runtime/test_core.py +++ b/src/bindings/python/tests/test_runtime/test_core.py @@ -153,7 +153,7 @@ def test_read_model_from_ir_with_user_config(request, tmp_path): core_cache_dir = core.get_property("CACHE_DIR") cache_path = tmp_path / Path("cache") - model = core.read_model(xml_path, bin_path, config={"CACHE_DIR": cache_path}) + model = core.read_model(xml_path, bin_path, config={"CACHE_DIR": f"{cache_path}"}) assert isinstance(model, Model) assert core_cache_dir == core.get_property("CACHE_DIR") diff --git a/src/bindings/python/tests/test_runtime/test_properties.py b/src/bindings/python/tests/test_runtime/test_properties.py index f7617212bd23b2..48e82234b269be 100644 --- a/src/bindings/python/tests/test_runtime/test_properties.py +++ b/src/bindings/python/tests/test_runtime/test_properties.py @@ -5,6 +5,7 @@ import pytest import numpy as np import os +from pathlib import Path import openvino as ov import openvino.properties as props @@ -646,6 +647,13 @@ def test_single_property_setting(device): assert isinstance(core.get_property(device, streams.num()), int) +def test_property_pathlib_path(device): + core = Core() + + core.set_property(device, {"CACHE_DIR": Path("./test_cache")}) + assert core.get_property(device, props.cache_dir) == str(Path("./test_cache")) + + @pytest.mark.skipif( os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason=f"Cannot run test on device {os.environ.get('TEST_DEVICE')}, Plugin specific test"