Skip to content

Commit

Permalink
[PyOV] Fix deprecation warnings for gcc (openvinotoolkit#24239)
Browse files Browse the repository at this point in the history
### Details:
 - *item1*
 - *...*

### Tickets:
 - CVS-139736
 - CVS-139194
  • Loading branch information
akuporos authored Apr 29, 2024
1 parent 55ff3aa commit 0b34324
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 52 deletions.
5 changes: 0 additions & 5 deletions src/bindings/python/src/pyopenvino/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions src/bindings/python/src/pyopenvino/core/remote_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
namespace py = pybind11;

void regclass_RemoteTensor(py::module m) {
py::class_<RemoteTensorWrapper, std::shared_ptr<RemoteTensorWrapper>> cls(m,
"RemoteTensor",
py::base<ov::Tensor>());
py::class_<RemoteTensorWrapper, std::shared_ptr<RemoteTensorWrapper>> cls(m, "RemoteTensor");

cls.def(
"get_device_name",
Expand Down
2 changes: 0 additions & 2 deletions src/bindings/python/src/pyopenvino/core/remote_tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <openvino/runtime/intel_gpu/properties.hpp>
#include <openvino/runtime/intel_gpu/remote_properties.hpp>
#include <openvino/runtime/remote_tensor.hpp>
#include <openvino/runtime/tensor.hpp>
#include <pyopenvino/core/tensor.hpp>

namespace py = pybind11;

Expand Down
63 changes: 21 additions & 42 deletions src/bindings/python/src/pyopenvino/frontend/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ov::frontend::GeneralFailure> exc(std::move(m), "GeneralFailure");
template <class T>
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<T> 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<ov::frontend::OpValidationFailure> exc(std::move(m), "OpValidationFailure");
#else
static py::handle ex = py::exception<T>(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<ov::frontend::GeneralFailure>(std::move(m), "GeneralFailure");
}

void regclass_frontend_OpValidationFailureFrontEnd(py::module m) {
handle_exception<ov::frontend::OpValidationFailure>(std::move(m), "OpValidationFailure");
}

void regclass_frontend_OpConversionFailureFrontEnd(py::module m) {
static py::exception<ov::frontend::OpConversionFailure> 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<ov::frontend::OpConversionFailure>(std::move(m), "OpConversionFailure");
}

void regclass_frontend_InitializationFailureFrontEnd(py::module m) {
static py::exception<ov::frontend::InitializationFailure> 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<ov::frontend::InitializationFailure>(std::move(m), "InitializationFailure");
}

void regclass_frontend_NotImplementedFailureFrontEnd(py::module m) {
static py::exception<ov::frontend::NotImplementedFailure> 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<ov::frontend::NotImplementedFailure>(std::move(m), "NotImplementedFailure");
}

OPENVINO_SUPPRESS_DEPRECATED_END
5 changes: 5 additions & 0 deletions src/bindings/python/src/pyopenvino/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions src/bindings/python/tests/test_runtime/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)

0 comments on commit 0b34324

Please sign in to comment.