OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[PyOV] Remove deprecated PostponedConstant overload (#33207)
Alicja Miloszewska6715267b0400
diff --git a/src/bindings/python/src/openvino/utils/postponed_constant.py b/src/bindings/python/src/openvino/utils/postponed_constant.pyindex e4a5ec6cffd..37616f8a7b2 100644--- a/src/bindings/python/src/openvino/utils/postponed_constant.py+++ b/src/bindings/python/src/openvino/utils/postponed_constant.py@@ -3,7 +3,7 @@# SPDX-License-Identifier: Apache-2.0-from typing import Optional, cast, overload+from typing import Optionalfrom collections.abc import Callablefrom openvino import Op, Type, Shape, Tensor, PartialShape, TensorVector@@ -15,20 +15,8 @@ class PostponedConstant(Op):to IR and then immediately disposes of it."""- @overloaddef __init__(self, element_type: Type, shape: Shape, maker: Callable[[], Tensor], name: Optional[str] = None- ) -> None:- ...-- @overload- def __init__(- self, element_type: Type, shape: Shape, maker: Callable[[Tensor], None], name: Optional[str] = None- ) -> None:- ...-- def __init__(- self, element_type: Type, shape: Shape, maker: Callable, name: Optional[str] = None) -> None:"""Creates a PostponedConstant.@@ -36,11 +24,8 @@ class PostponedConstant(Op)::type element_type: openvino.Type:param shape: Shape of the constant.:type shape: openvino.Shape- :param maker: A callable that returns a Tensor or modifies the provided Tensor to- represent the constant.- Note: It's recommended to use a callable without arguments (returns Tensor)- to avoid unnecessary tensor data copies.- :type maker: Union[Callable[[], Tensor], Callable[[Tensor], None]]+ :param maker: A callable that returns a Tensor.+ :type maker: Callable[[], Tensor]:param name: Optional name for the constant.:type name: Optional[str]@@ -60,30 +45,10 @@ class PostponedConstant(Op):self.m_maker = makerif name is not None:self.friendly_name = name-- if (- callable(self.m_maker)- and hasattr(self.m_maker.__call__, "__code__")- and self.m_maker.__call__.__code__.co_argcount > 1- ):- from openvino._pyopenvino.util import deprecation_warning-- deprecation_warning(- "PostponedConstant.__init__ with Callable[[Tensor], None]",- "2026.0",- "Please use PostponedConstant's 'maker' argument as Callable[[], Tensor] "- "instead of Callable[[Tensor], None].",- 3,- )-self.constructor_validate_and_infer_types()def evaluate(self, outputs: TensorVector, _: list[Tensor]) -> bool: # type: ignore- num_args = self.m_maker.__call__.__code__.co_argcount- if num_args == 1:- outputs[0] = cast(Callable[[], Tensor], self.m_maker)()- else:- cast(Callable[[Tensor], None], self.m_maker)(outputs[0])+ outputs[0] = self.m_maker()return Truedef validate_and_infer_types(self) -> None:@@ -97,5 +62,8 @@ class PostponedConstant(Op):# `maker` is a function that returns ov.Tensor that represents a target Constant-def make_postponed_constant(element_type: Type, shape: Shape, maker: Callable, name: Optional[str] = None) -> Op:+def make_postponed_constant(element_type: Type,+ shape: Shape,+ maker: Callable[[], Tensor],+ name: Optional[str] = None) -> Op:return PostponedConstant(element_type, shape, maker, name)diff --git a/src/bindings/python/tests/test_utils/test_utils.py b/src/bindings/python/tests/test_utils/test_utils.pyindex 0e283df6b53..e3a9499564e 100644--- a/src/bindings/python/tests/test_utils/test_utils.py+++ b/src/bindings/python/tests/test_utils/test_utils.py@@ -104,20 +104,6 @@ def test_cmake_file_not_found(monkeypatch):assert result == ""-# For backward compatibility with old maker signatures-class MakerTensorCopy:- def __init__(self):- self.calls_count = 0-- def __call__(self, tensor: ov.Tensor) -> None:- self.calls_count += 1- tensor_data = np.array([2, 2, 2, 2], dtype=np.float32).reshape(1, 1, 2, 2)- ov.Tensor(tensor_data).copy_to(tensor)-- def called_times(self):- return self.calls_count--class Maker:def __init__(self):self.calls_count = 0@@ -191,28 +177,6 @@ def test_serialize_postponned_constant(prepare_ir_paths):assert maker.called_times() == 1-def test_serialize_postponned_constant_maker_tensor_copy(prepare_ir_paths):- maker = MakerTensorCopy()- with pytest.warns(- DeprecationWarning,- match=(- "PostponedConstant.__init__ with Callable\\[\\[Tensor\\], None\\] "- "is deprecated and will be removed in version 2026.0"- ),- ) as w:- model = create_model(maker)- assert issubclass(w[0].category, DeprecationWarning)- assert (- "Please use PostponedConstant's 'maker' argument as Callable[[], Tensor] "- "instead of Callable[[Tensor], None]"- ) in str(w[0].message)- assert maker.called_times() == 0-- model_export_file_name, weights_export_file_name = prepare_ir_paths- ov.serialize(model, model_export_file_name, weights_export_file_name)- assert maker.called_times() == 1--def test_infer_postponned_constant():maker = Maker()model = create_model(maker)