Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[PyOV] Add check for returned empty map from get_property (#36009)

Alexandru Enache7bea460949ef
diff --git a/src/bindings/python/src/pyopenvino/utils/utils.cpp b/src/bindings/python/src/pyopenvino/utils/utils.cpp
index 4c4a12bd600..4b1a2669dcd 100644
--- a/src/bindings/python/src/pyopenvino/utils/utils.cpp
+++ b/src/bindings/python/src/pyopenvino/utils/utils.cpp
@@ -106,6 +106,10 @@ py::object from_ov_any_map(const ov::AnyMap& map) {
}
py::object from_ov_any(const ov::Any& any) {
+ // Empty Any (e.g. write-only property queried via get_property)
+ if (any.empty()) {
+ return py::none();
+ }
// Check for py::object
if (any.is<std::shared_ptr<py::object>>()) {
return *any.as<std::shared_ptr<py::object>>();
diff --git a/src/bindings/python/tests/test_graph/test_any.py b/src/bindings/python/tests/test_graph/test_any.py
index 86f6411ecdc..262963c8ae7 100644
--- a/src/bindings/python/tests/test_graph/test_any.py
+++ b/src/bindings/python/tests/test_graph/test_any.py
@@ -73,6 +73,12 @@ def test_any_class():
assert value.value.text == "test"
+def test_any_empty():
+ ovany = OVAny(None)
+ assert ovany.value is None
+ assert ovany.get() is None
+
+
@pytest.mark.parametrize(("value", "dtype"), [
("some_value", str),
(31.23456, float),