Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Py OV] Fix openvino.Model mocked object parameters #28313

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/bindings/python/src/openvino/_ov_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
)


class Model:
class ModelMeta(type):
def __dir__(cls) -> list:
return list(set(cls.__dict__.keys()) | set(dir(ModelBase)))


class Model(object, metaclass=ModelMeta):
def __init__(self, *args: Any, **kwargs: Any) -> None:
if args and not kwargs:
if isinstance(args[0], ModelBase):
Expand Down Expand Up @@ -67,6 +72,10 @@ def __exit__(self, exc_type: Type[BaseException], exc_value: BaseException, trac
def __repr__(self) -> str:
return self.__model.__repr__()

def __dir__(self) -> list:
wrapper_methods = ["__copy__", "__deepcopy__", "__dict__", "__enter__", "__exit__", "__getattr__", "__weakref__"]
return dir(self.__model) + wrapper_methods


class InferRequest(_InferRequestWrapper):
"""InferRequest class represents infer request which can be run in asynchronous or synchronous manners."""
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 @@ -849,3 +849,11 @@ def test_tempdir_save_load_error():
with tempfile.TemporaryDirectory() as model_save_dir:
save_model(mem_model, f"{model_save_dir}/model.xml")
_ = Core().read_model(f"{model_save_dir}/model.xml")


def test_model_dir():
model = generate_add_model()
num_of_attrs = 83

assert type(dir(model)) == list
assert len(dir(model)) == num_of_attrs
Loading