Skip to content

Fix Pyright errors in utils/types.py #30196

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion src/bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ include = '\.pyi?$'
[tool.pyright]
exclude = [
"src/openvino/utils/data_helpers/data_dispatcher.py",
"src/openvino/utils/types.py",
"src/openvino/**/ops.py",
"src/openvino/utils/decorators.py",
"src/openvino/frontend/frontend.py",
Expand Down
12 changes: 6 additions & 6 deletions src/bindings/python/src/openvino/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
NumericData = Union[int, float, np.ndarray]
NumericType = Union[type, np.dtype]
ScalarData = Union[int, float]
NodeInput = Union[Node, NumericData]
NodeInput = Union[Node, Output, NumericData]

openvino_to_numpy_types_map = [
(Type.boolean, bool),
Expand Down Expand Up @@ -145,7 +145,7 @@ def get_shape(data: NumericData) -> TensorShape:
return []


def make_constant_node(value: NumericData, dtype: Union[NumericType, Type] = None, *, name: Optional[str] = None) -> Constant:
def make_constant_node(value: NumericData, dtype: Optional[Union[NumericType, Type]] = None, *, name: Optional[str] = None) -> Constant:
"""Return an openvino Constant node with the specified value."""
ndarray = get_ndarray(value)
if dtype is not None:
Expand All @@ -161,15 +161,15 @@ def make_constant_node(value: NumericData, dtype: Union[NumericType, Type] = Non
return const


def as_node(input_value: NodeInput, name: Optional[str] = None) -> Union[Node, Output]:
def as_node(input_value: NodeInput, name: Optional[str] = None) -> Union[Node, Output, Constant]:
"""Return input values as nodes. Scalars will be converted to Constant nodes."""
if issubclass(type(input_value), Node):
if isinstance(input_value, Node):
return input_value
if issubclass(type(input_value), Output):
if isinstance(input_value, Output):
return input_value
return make_constant_node(input_value, name=name)


def as_nodes(*input_values: NodeInput, name: Optional[str] = None) -> List[Node]:
def as_nodes(*input_values: NodeInput, name: Optional[str] = None) -> List[Union[Node, Output]]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def as_nodes(*input_values: NodeInput, name: Optional[str] = None) -> List[Union[Node, Output]]:
def as_nodes(*input_values: NodeInput, name: Optional[str] = None) -> List[Union[Node, Output, Constant]]:

because as_node returns Union[Node, Output, Constant] several lines above

"""Return input values as nodes. Scalars will be converted to Constant nodes."""
return [as_node(input_value, name=name) for input_value in input_values]
Loading