diff --git a/src/bindings/python/src/pyopenvino/CMakeLists.txt b/src/bindings/python/src/pyopenvino/CMakeLists.txt index 23b67586671e8b..086cd622643e02 100644 --- a/src/bindings/python/src/pyopenvino/CMakeLists.txt +++ b/src/bindings/python/src/pyopenvino/CMakeLists.txt @@ -30,11 +30,6 @@ elseif(CMAKE_COMPILER_IS_GNUCXX) ov_add_compiler_flags(-Wno-error=attributes) endif() -if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG OR OV_COMPILER_IS_INTEL_LLVM) - # TODO: remove this deprecated API usage - ov_add_compiler_flags(-Wno-error=deprecated-declarations) -endif() - if(ENABLE_TESTS) add_subdirectory(test_utils) endif() diff --git a/src/bindings/python/src/pyopenvino/core/remote_tensor.cpp b/src/bindings/python/src/pyopenvino/core/remote_tensor.cpp index 034b9b425b7634..141e1eaa39c47d 100644 --- a/src/bindings/python/src/pyopenvino/core/remote_tensor.cpp +++ b/src/bindings/python/src/pyopenvino/core/remote_tensor.cpp @@ -12,9 +12,7 @@ namespace py = pybind11; void regclass_RemoteTensor(py::module m) { - py::class_> cls(m, - "RemoteTensor", - py::base()); + py::class_> cls(m, "RemoteTensor"); cls.def( "get_device_name", diff --git a/src/bindings/python/src/pyopenvino/core/remote_tensor.hpp b/src/bindings/python/src/pyopenvino/core/remote_tensor.hpp index 4fa40aff49615d..a35443fd6f2f94 100644 --- a/src/bindings/python/src/pyopenvino/core/remote_tensor.hpp +++ b/src/bindings/python/src/pyopenvino/core/remote_tensor.hpp @@ -9,8 +9,6 @@ #include #include #include -#include -#include namespace py = pybind11; diff --git a/src/bindings/python/src/pyopenvino/frontend/manager.cpp b/src/bindings/python/src/pyopenvino/frontend/manager.cpp index f197d6946f8cab..a824e9473bc181 100644 --- a/src/bindings/python/src/pyopenvino/frontend/manager.cpp +++ b/src/bindings/python/src/pyopenvino/frontend/manager.cpp @@ -99,68 +99,47 @@ void regclass_frontend_FrontEndManager(py::module m) { }); } -OPENVINO_SUPPRESS_DEPRECATED_START - -// CVS-139194: migrate to new exception handling https://github.com/pybind/pybind11/pull/4772 - -void regclass_frontend_GeneralFailureFrontEnd(py::module m) { - static py::exception exc(std::move(m), "GeneralFailure"); +template +void handle_exception(py::module m, const char* exc_type) { +#if PYBIND11_VERSION_MAJOR < 2 || (PYBIND11_VERSION_MAJOR == 2 && PYBIND11_VERSION_MINOR < 12) + static py::exception exc(std::move(m), exc_type); py::register_exception_translator([](std::exception_ptr p) { try { if (p) std::rethrow_exception(p); - } catch (const ov::frontend::GeneralFailure& e) { + } catch (const T& e) { exc(e.what()); } }); -} - -void regclass_frontend_OpValidationFailureFrontEnd(py::module m) { - static py::exception exc(std::move(m), "OpValidationFailure"); +#else + static py::handle ex = py::exception(std::move(m), exc_type).release(); py::register_exception_translator([](std::exception_ptr p) { try { if (p) std::rethrow_exception(p); - } catch (const ov::frontend::OpValidationFailure& e) { - exc(e.what()); + } catch (const T& e) { + py::set_error(ex, e.what()); } }); +#endif +} + +void regclass_frontend_GeneralFailureFrontEnd(py::module m) { + handle_exception(std::move(m), "GeneralFailure"); +} + +void regclass_frontend_OpValidationFailureFrontEnd(py::module m) { + handle_exception(std::move(m), "OpValidationFailure"); } void regclass_frontend_OpConversionFailureFrontEnd(py::module m) { - static py::exception exc(std::move(m), "OpConversionFailure"); - py::register_exception_translator([](std::exception_ptr p) { - try { - if (p) - std::rethrow_exception(p); - } catch (const ov::frontend::OpConversionFailure& e) { - exc(e.what()); - } - }); + handle_exception(std::move(m), "OpConversionFailure"); } void regclass_frontend_InitializationFailureFrontEnd(py::module m) { - static py::exception exc(std::move(m), "InitializationFailure"); - py::register_exception_translator([](std::exception_ptr p) { - try { - if (p) - std::rethrow_exception(p); - } catch (const ov::frontend::InitializationFailure& e) { - exc(e.what()); - } - }); + handle_exception(std::move(m), "InitializationFailure"); } void regclass_frontend_NotImplementedFailureFrontEnd(py::module m) { - static py::exception exc(std::move(m), "NotImplementedFailure"); - py::register_exception_translator([](std::exception_ptr p) { - try { - if (p) - std::rethrow_exception(p); - } catch (const ov::frontend::NotImplementedFailure& e) { - exc(e.what()); - } - }); + handle_exception(std::move(m), "NotImplementedFailure"); } - -OPENVINO_SUPPRESS_DEPRECATED_END diff --git a/src/bindings/python/src/pyopenvino/utils/utils.hpp b/src/bindings/python/src/pyopenvino/utils/utils.hpp index e2e5c6f5e886ff..1e0e7f23069d2e 100644 --- a/src/bindings/python/src/pyopenvino/utils/utils.hpp +++ b/src/bindings/python/src/pyopenvino/utils/utils.hpp @@ -12,10 +12,15 @@ // Generated by operator `==` inside pybind::handle. #pragma warning( push ) #pragma warning( disable: 4996 ) +#elif defined(__GNUC__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif #include "openvino/core/any.hpp" #ifdef _MSC_VER #pragma warning( pop ) +#elif defined(__GNUC__) + #pragma GCC diagnostic pop #endif #include "openvino/core/type/element_type.hpp" diff --git a/src/bindings/python/tests/test_runtime/test_model.py b/src/bindings/python/tests/test_runtime/test_model.py index 6d545f7760cf3d..65bef9a2ac0f6c 100644 --- a/src/bindings/python/tests/test_runtime/test_model.py +++ b/src/bindings/python/tests/test_runtime/test_model.py @@ -7,6 +7,7 @@ import pytest import math from contextlib import nullcontext as does_not_raise +from copy import copy import openvino.runtime.opset13 as ops from openvino import ( @@ -573,3 +574,10 @@ def test_save_model_with_none(): with pytest.raises(AttributeError) as e: save_model(model=None, output_model="model.xml") assert "'model' argument is required and cannot be None." in str(e.value) + + +def test_copy_failed(): + model = generate_add_model() + with pytest.raises(TypeError) as e: + copy(model) + assert "cannot copy 'openvino.runtime.Model. Please, use deepcopy instead." in str(e.value)