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

SNOW-1791994 IR: Generate typed protobuf Python code #2593

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

sfc-gh-azhan
Copy link
Collaborator

@sfc-gh-azhan sfc-gh-azhan commented Nov 8, 2024

  1. Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-1791994

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
      • If this test skips Local Testing mode, I'm requesting review from @snowflakedb/local-testing
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am adding new credentials
    • I am adding a new dependency
    • If this is a new feature/behavior, I'm adding the Local Testing parity changes.
    • I acknowledge that I have ensured my changes to be thread-safe. Follow the link for more information: Thread-safe Developer Guidelines
  3. Please describe how your code solves the related issue.

    Please write a short description of how your code change solves the related issue.

This PR generates typed Python code from protobuf and make sure CI check types in precommit.

Copilot summary:
This pull request includes several changes to improve type checking, streamline the build process, and enhance code quality. The most important changes include the addition of mypy-protobuf for generating typed Python code from protobuf, updates to the build and pre-commit configurations, and improvements to type annotations across various files.

Build and Dependency Management:

  • Added mypy-protobuf installation in .github/scripts/install_protoc.sh and scripts/jenkins_regress.sh to generate typed Python code from protobuf. [1] [2] [3]
  • Updated .github/workflows/precommit.yml to install tox and streamline the documentation build process using tox.
  • Modified setup.py to include mypy-protobuf as a dependency and updated the protobuf generation command to use --mypy_out. [1] [2] [3]

Pre-commit Configuration:

  • Added new files and dependencies to the mypy check in .pre-commit-config.yaml. [1] [2]

Code Quality and Type Annotations:

  • Enhanced type annotations in src/snowflake/snowpark/_internal/ast/batch.py by specifying return types and dictionary types. [1] [2] [3]
  • Improved type checking in src/snowflake/snowpark/_internal/ast/utils.py by adding # type: ignore comments and TODOs for better handling of type issues. [1] [2] [3] [4] [5] [6]

Tested Jenkins jobs:

@sfc-gh-azhan sfc-gh-azhan added NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md NO-PANDAS-CHANGEDOC-UPDATES This PR does not update Snowpark pandas docs labels Nov 8, 2024
@sfc-gh-azhan sfc-gh-azhan force-pushed the azhan-proto-type-1791994 branch 8 times, most recently from 9f796a2 to 6d9ab25 Compare November 10, 2024 06:00
@sfc-gh-azhan sfc-gh-azhan force-pushed the azhan-proto-type-1791994 branch 4 times, most recently from c7e0af0 to 6e576e7 Compare November 11, 2024 06:25
@sfc-gh-azhan sfc-gh-azhan changed the title Azhan proto type 1791994 SNOW-1791994 IR: Generate typed protobuf Python codeAzhan proto type 1791994 Nov 11, 2024
run: |
make clean
make html SPHINXOPTS="-W --keep-going"
run: python -m tox -e docs
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just reuse the same code in tox

@@ -91,6 +91,7 @@ repos:
- id: mypy
files: >
(?x)^(
src/snowflake/snowpark/_internal/ast/.*\.py|
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cover all ast code in mypy type check

@@ -80,14 +80,14 @@ def __init__(self) -> None: # pragma: no cover
self.symbols: Optional[Union[str, List[str]]] = None

# TODO(SNOW-1491199) - This method is not covered by tests until the end of phase 0. Drop the pragma when it is covered.
def visit_Assign(self, node) -> None: # pragma: no cover
def visit_Assign(self, node: ast.Assign) -> None: # pragma: no cover
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we should fix those once our code is in.

@sfc-gh-azhan sfc-gh-azhan marked this pull request as ready for review November 11, 2024 19:16
@sfc-gh-azhan sfc-gh-azhan requested review from a team as code owners November 11, 2024 19:16
@sfc-gh-azhan sfc-gh-azhan changed the title SNOW-1791994 IR: Generate typed protobuf Python codeAzhan proto type 1791994 SNOW-1791994 IR: Generate typed protobuf Python code Nov 11, 2024
):
stmt = func._ast_stmt
fn_expr = expr.fn.indirect_table_fn_id_ref
stmt = func._ast_stmt # type: ignore[union-attr] # TODO(SNOW-1491199) # Item "str" of "Union[str, list[str], TableFunctionCall, Callable[..., Any]]" has no attribute "_ast_stmt", Item "list[str]" of "Union[str, list[str], TableFunctionCall, Callable[..., Any]]" has no attribute "_ast_stmt", Item "TableFunctionCall" of "Union[str, list[str], TableFunctionCall, Callable[..., Any]]" has no attribute "_ast_stmt", Item "function" of "Union[str, list[str], TableFunctionCall, Callable[..., Any]]" has no attribute "_ast_stmt"
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume the comments are machine-generated. Does any particular linter or annotation checker require the full message? Looks pretty cumbersome.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it contains three parts:

  1. jira no. to track
  2. the type ignore
  3. the error message
    It's probably verbose for the error message but I try to capture them so when we fix them later, we can easily know what was the issue before.

@sfc-gh-oplaton
Copy link
Contributor

Thank you for setting this up! Generally looks good. I did not review _internal/ast/*.py in detail, I assume all comments are machine-generated to silence warnings.

@@ -57,6 +57,7 @@
"pytest-assume", # sql counter check
"decorator", # sql counter check
"protoc-wheel-0==21.1", # Protocol buffer compiler, for Snowpark IR
"mypy-protobuf", # used in generating typed Python code from protobuf for Snowpark IR
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this has no licensing or security concerns, either. Should this require a specific minimum version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is development requirements so should be fine.

@sfc-gh-azhan sfc-gh-azhan merged commit fb0fa7b into main Nov 11, 2024
41 of 42 checks passed
@sfc-gh-azhan sfc-gh-azhan deleted the azhan-proto-type-1791994 branch November 11, 2024 21:13
@github-actions github-actions bot locked and limited conversation to collaborators Nov 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md NO-PANDAS-CHANGEDOC-UPDATES This PR does not update Snowpark pandas docs snowpark-pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants