Skip to content

Fix #30150: Fix Pyright errors in frontend/frontend.py #30195

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

Closed
wants to merge 10 commits into from

Conversation

sanleo-wq
Copy link

Description

This PR fixes issue #30150 by resolving the Pyright errors in the src/openvino/frontend/frontend.py file.

Changes made

  • Added proper type annotations with cast() from the typing module
  • Used Optional[FrontEnd] instead of Union[FrontEnd, None] for better readability
  • Added targeted # type: ignore comments with explanations where there is an inherent type incompatibility between openvino.Model and openvino._pyopenvino.Model
  • Removed the file from exclusions in pyproject.toml

Testing

  • Removed src/openvino/frontend/frontend.py from the exclusions in pyproject.toml
  • Ran Pyright which now reports no errors:

@sanleo-wq sanleo-wq requested a review from a team as a code owner April 17, 2025 15:47
@github-actions github-actions bot added the category: Python API OpenVINO Python bindings label Apr 17, 2025
@sys-openvino-ci sys-openvino-ci added the ExternalPR External contributor label Apr 17, 2025
@mlukasze mlukasze requested a review from rkazants April 18, 2025 05:05
@p-wysocki
Copy link
Contributor

Thank you for the PR! Could you please also regenerate .pyi files as mentioned in the issue description? All you need to do is build OpenVINO with -DENABLE_WHEEL=ON, install that wheel python -m pip install build/wheels/openvino... and either:

  • make any commit, and the .pyi files will be automatically regenerated and added to your commit
  • run python src/bindings/python/scripts/generate_stub_files.py and git add them manually

Co-authored-by: Anastasia Kuporosova <anastasia.kuporosova@intel.com>
Copy link
Contributor

@p-wysocki p-wysocki left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! Looks good to me.

@github-actions github-actions bot added the category: TF FE OpenVINO TensorFlow FrontEnd label Apr 24, 2025
Comment on lines 1 to -23
# type: ignore
from . import _op_base
from . import _ov_api
from . import _pyopenvino
from . import exceptions
from . import experimental
from . import frontend
from . import helpers
from . import op
from . import opset1
from . import opset10
from . import opset11
from . import opset12
from . import opset13
from . import opset14
from . import opset15
from . import opset16
from . import opset2
from . import opset3
from . import opset4
from . import opset5
from . import opset6
from . import opset7
Copy link
Member

Choose a reason for hiding this comment

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

looks a lot undesired changes

Copy link
Member

@rkazants rkazants left a comment

Choose a reason for hiding this comment

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

looks a lot undesired changes among different files

@@ -21,7 +21,7 @@ def create_regex_pattern(errors):
return "|".join([re.escape(error) for error in errors])

def sanitize_file(file_path):
with open(file_path, 'r') as file:
with open(file_path, 'r', encoding='utf-8') as file:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was it needed? Not saying it's unnecessary, I'm curious - it's a new script and something may be missing.

Copy link
Author

Choose a reason for hiding this comment

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

Because when i ran the file whit the command: python src/bindings/python/scripts/generate_stub_files.py
give e this errors:

Traceback (most recent call last):
File "openvino\src\bindings\python\scripts\generate_pyapi_stubs.py", line 101, in
main()

File "openvino\src\bindings\python\scripts\generate_pyapi_stubs.py", line 98, in main
sanitize_file(file_path)

File "openvino\src\bindings\python\scripts\generate_pyapi_stubs.py", line 25, in sanitize_file
content = file.readlines()

File "Lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2010: character maps to

The error occurs because the script tries to read files using the default encoding cp1252 in Windows, but some files contain Unicode characters that aren't supported by this encoding.

By explicitly specifying encoding='utf-8' I was able to generate the pyi files.

@p-wysocki
Copy link
Contributor

Thank you for the investigation! The tasks for fixing pyright seemed straightforward, but when reviewing the PRs we decided that it's a much more difficult issue than we expected and, combined with the task priority, we decided to move fixes for pyright checks back as an internal OpenVINO team effort. It's no longer an open Good First Issue - we apologize for closing the task you were working on, your contribution helped us investigate that issue.

@p-wysocki p-wysocki closed this Apr 25, 2025
@sanleo-wq sanleo-wq deleted the fix-30150 branch April 28, 2025 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: Python API OpenVINO Python bindings category: TF FE OpenVINO TensorFlow FrontEnd ExternalPR External contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Good First Issue]: Fix pyright in: src/openvino/frontend/frontend.py
5 participants