Repository navigation
[PyOV] Return a shallow copy from OVDict.to_dict - #39179
Open
Somay-kousis wants to merge 1 commit into
Open
Somay-kousis wants to merge 1 commit into
Somay-kousis wants to merge 1 commit into
Conversation
Signed-off-by: Somay-kousis <somaykaush@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details:
What a user sees:
result.to_dict().clear()emptiesresult, becauseto_dict()returns the OVDict's own dictionary. The docstrings say OVDict is immutable andto_dictreturns a shallow copy.result.to_dict() is result.to_dict()TrueFalsed = result.to_dict(); d.clear(); len(result)0result.to_dict()[port] is result[port](same array)TrueTrueFix:
to_dictreturnsdict(self._dict). The arrays are still shared, so writing into an array in place still shows in the OVDict, as the docstring says ("modifications to returned values may affect this class"). The summary line now says it returns a shallow copy, inwrappers.pyandwrappers.pyi.Behaviour change: code that added or removed keys in
to_dict()to change the OVDict no longer does. I found no such use in openvinotoolkit repos (git grepover master, GitHub code search).New test
test_ovdict_to_dict_returns_shallow_copyintests/test_runtime/test_ovdict.py.Tickets:
AI Assistance:
wrappers.py:wrappers.pyboth fail (len(result) == 0afterclear()). A deep copy also fails them, since the test checks the arrays are the same objects.test_ovdict.py: 22 passed.test_sync_infer_request.py,test_async_infer_request.py,test_compiled_model.py: 221 passed, 7 skipped.wrappers.py: clean.