Skip to content

Comments

style(fuzz): Modernize type annotations to Python 3.10+ syntax#251

Merged
Hzfengsy merged 1 commit intohw-native-sys:mainfrom
lwDavid:fix
Feb 24, 2026
Merged

style(fuzz): Modernize type annotations to Python 3.10+ syntax#251
Hzfengsy merged 1 commit intohw-native-sys:mainfrom
lwDavid:fix

Conversation

@lwDavid
Copy link
Contributor

@lwDavid lwDavid commented Feb 24, 2026

style(fuzz): modernize type annotations to Python 3.10+ syntax

Replace legacy typing imports (Dict, List, Tuple, Optional) with
built-in generics (dict, list, tuple) and union syntax (X | None)
across all fuzz test source files. Also fix minor README formatting
(code block language tag, blank lines before lists, table alignment).

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @lwDavid, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the maintainability and readability of the fuzz testing framework by adopting modern Python type hinting conventions. The changes primarily involve updating type annotations to align with Python 3.10+ syntax, which simplifies the code and improves type checking. Additionally, minor documentation formatting adjustments were made to ensure consistency and clarity.

Highlights

  • Type Annotation Modernization: Updated Python type annotations across all fuzz test source files to use the Python 3.10+ syntax, replacing legacy typing imports like Dict, List, Tuple, and Optional with built-in generics (dict, list, tuple) and union syntax (X | None).
  • README Formatting Improvements: Applied minor formatting fixes to the tests/st/fuzz/README.md file, including updating code block language tags, adding blank lines before lists, and adjusting table alignment for better readability.
Changelog
  • tests/st/fuzz/README.md
    • Updated code block language tag to 'text'
    • Added blank lines before list items
    • Adjusted table header alignment
  • tests/st/fuzz/src/fuzzer.py
    • Replaced typing.Dict with dict
    • Replaced typing.List with list
    • Replaced typing.Tuple with tuple
    • Replaced typing.Optional[X] with X | None
  • tests/st/fuzz/src/kernel_generator.py
    • Replaced typing.Dict with dict
    • Replaced typing.List with list
    • Replaced typing.Tuple with tuple
    • Replaced typing.Optional[X] with X | None
  • tests/st/fuzz/src/multi_kernel_test_generator.py
    • Replaced typing.Dict with dict
    • Replaced typing.List with list
    • Replaced typing.Tuple with tuple
    • Replaced typing.Optional[X] with X | None
  • tests/st/fuzz/src/orchestrator_generator.py
    • Replaced typing.Dict with dict
    • Replaced typing.List with list
    • Replaced typing.Tuple with tuple
    • Replaced typing.Optional[X] with X | None
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 2026

📝 Walkthrough

Walkthrough

The pull request modernizes Python type hints across the fuzzing test framework from typing module imports (List, Dict, Optional, Tuple) to Python 3.9+ built-in generics (list, dict, tuple, | union syntax). Documentation is enhanced with new configuration parameters and component descriptions.

Changes

Cohort / File(s) Summary
Documentation
tests/st/fuzz/README.md
Code fences updated, blank lines added for readability. Expanded OpFuzzer, KernelGenerator, and OrchestratorGenerator descriptions. Introduced MultiKernelTestGenerator component reference. Extended Configuration Options table with --rtol and --advanced-ops-prob parameters.
Type Hint Modernization - Fuzzer
tests/st/fuzz/src/fuzzer.py
Updated typing annotations across OpSpec dataclass and OpFuzzer class from typing module to built-in generics. Affected signatures: is_shape_aligned, get_aligned_shapes, generate_aligned_shape, compute_output_shape, generate_params, compute_output_range, generate_op_chain, and internal range computation methods.
Type Hint Modernization - Kernel Generator
tests/st/fuzz/src/kernel_generator.py
Modernized KernelGenerator.init, generate_kernel, _generate_input_loads, _generate_reduction_op, _generate_store_op, _generate_kernel_code, and generate_multiple_kernels signatures from typing module to Python built-in generics.
Type Hint Modernization - Multi-Kernel Test Generator
tests/st/fuzz/src/multi_kernel_test_generator.py
Systematically updated type hints in init, _generate_tensor_init_value, _compute_output_shapes_for_sequential, _regenerate_kernel_code_with_unified_shapes, generate_test_case, _generate_torch_reference, _get_torch_operation, _generate_test_class, and _validate_golden_output.
Type Hint Modernization - Orchestrator Generator
tests/st/fuzz/src/orchestrator_generator.py
Updated init, generate_sequential, generate_branching, generate_mixed, and generate_merge_kernel signatures from typing module to built-in generic types (list, dict, tuple,

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 With types modernized from old to new,
Our fuzzing framework gets a fresh debut,
From List and Dict to list and dict so true,
Built-in generics make the code shine through! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: modernizing type annotations to Python 3.10+ syntax across the fuzz test files.
Description check ✅ Passed The description is directly related to the changeset, explaining the replacement of legacy typing with built-in generics and minor README formatting fixes, which aligns with the actual changes made.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively modernizes the type annotations in the fuzz testing framework to the Python 3.10+ syntax, replacing legacy typing imports with built-in generics and the | union operator. The changes are consistent and correctly applied across all fuzz test source files, improving code readability and adhering to modern Python standards. Additionally, the formatting fixes in README.md enhance the documentation's clarity. The implementation is solid, and I have no further suggestions for improvement.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
tests/st/fuzz/src/fuzzer.py (1)

1077-1085: Mark default_shape as intentionally unused.
default_shape isn’t referenced in _try_expand_row_vec and _try_expand_col_vec (Line 1084, Line 1166), which triggers ARG002. Consider explicitly marking it unused.

♻️ Suggested lint-silencing tweak
@@
     def _try_expand_row_vec(
         self,
         row_vec_name: str,
         operations: list[dict[str, Any]],
         available_tiles: list[str],
         variable_shapes: dict[str, tuple[int, int]],
         variable_usage_count: dict[str, int],
         default_shape: tuple[int, int],
         next_tmp_index: int,
     ) -> int:
+        _ = default_shape  # reserved for future fallback logic
         #  [M, N]  tile (N != 1)
@@
     def _try_expand_col_vec(
         self,
         col_vec_name: str,
         operations: list[dict[str, Any]],
         available_tiles: list[str],
         variable_shapes: dict[str, tuple[int, int]],
         variable_usage_count: dict[str, int],
         variable_ranges: dict[str, "ValueRange"],
         default_shape: tuple[int, int],
         next_tmp_index: int,
     ) -> int:
+        _ = default_shape  # reserved for future fallback logic
         # Get [1, N] shape

Also applies to: 1158-1167

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/st/fuzz/src/fuzzer.py` around lines 1077 - 1085, The parameter
default_shape in the functions _try_expand_row_vec and _try_expand_col_vec is
intentionally unused and triggers ARG002; rename the parameter to _default_shape
(or prefix it with an underscore) in both function signatures and any callers to
signal it is intentionally unused and silence the lint warning, ensuring you
update the identifiers for _try_expand_row_vec and _try_expand_col_vec
consistently.
tests/st/fuzz/src/multi_kernel_test_generator.py (1)

307-309: Silence unused-parameter warnings for orch_info / shape.
orch_info and shape are not referenced (Line 308, Line 656–657), so Ruff raises ARG002. Consider marking them intentionally unused.

♻️ Suggested lint-silencing tweak
@@
     def _generate_torch_reference(
         self,
         kernels: list[dict[str, Any]],
         orch_info: dict[str, Any],
     ) -> str:
+        _ = orch_info  # reserved for future use
         """Torch reference implementation
@@
     def _validate_golden_output(  # noqa: PLR0912
         self,
         kernels: list[dict[str, Any]],
         orch_info: dict[str, Any],
         shape: tuple[int, int],
         tensor_init_type: str,
     ) -> None:
+        _ = orch_info  # reserved for future use
+        _ = shape      # reserved for future use
         """golden , NaN/Inf

Also applies to: 655-658

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/st/fuzz/src/multi_kernel_test_generator.py` around lines 307 - 309, The
parameters orch_info and shape in multi_kernel_test_generator.py are unused and
trigger ARG002; silence this by marking them intentionally unused: either rename
them to _orch_info and _shape in the function signatures that declare them, or
add a single-line no-op reference inside the function body (e.g. _ = orch_info;
_ = shape) or append a per-parameter noqa comment (e.g. # noqa: ARG002) — do
this for every function that declares orch_info and shape so Ruff stops flagging
them.
tests/st/fuzz/src/orchestrator_generator.py (1)

35-39: Silence Ruff ARG002 for the unused shape parameter.
shape isn’t referenced in these methods (Line 38, Line 112), which triggers lint noise. Consider explicitly marking it unused to keep the public signature intact.

♻️ Suggested lint-silencing tweak
@@
     def generate_sequential(
         self,
         kernels: list[dict[str, Any]],
         shape: tuple[int, int] = (128, 128),
     ) -> dict[str, Any]:
+        _ = shape  # reserved for future shape-specific logic
         if not kernels:
             raise ValueError("kernels")
@@
     def generate_branching(
         self,
         kernels: list[dict[str, Any]],
         shape: tuple[int, int] = (128, 128),
     ) -> dict[str, Any]:
+        _ = shape  # reserved for future shape-specific logic
         if not kernels:
             raise ValueError("kernels")

Also applies to: 109-113

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/st/fuzz/src/orchestrator_generator.py` around lines 35 - 39, The shape
parameter is unused but must remain in the public signature; to silence Ruff
ARG002, consume it inside the function body (without changing the parameter
name) by assigning it to a throwaway variable—e.g. add a line like _ = shape  #
silence ruff ARG002—inside generate_sequential and the other generator method
that also accepts shape (the one around lines 109–113) so the parameter is
considered used while the signature stays intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/st/fuzz/src/fuzzer.py`:
- Around line 1077-1085: The parameter default_shape in the functions
_try_expand_row_vec and _try_expand_col_vec is intentionally unused and triggers
ARG002; rename the parameter to _default_shape (or prefix it with an underscore)
in both function signatures and any callers to signal it is intentionally unused
and silence the lint warning, ensuring you update the identifiers for
_try_expand_row_vec and _try_expand_col_vec consistently.

In `@tests/st/fuzz/src/multi_kernel_test_generator.py`:
- Around line 307-309: The parameters orch_info and shape in
multi_kernel_test_generator.py are unused and trigger ARG002; silence this by
marking them intentionally unused: either rename them to _orch_info and _shape
in the function signatures that declare them, or add a single-line no-op
reference inside the function body (e.g. _ = orch_info; _ = shape) or append a
per-parameter noqa comment (e.g. # noqa: ARG002) — do this for every function
that declares orch_info and shape so Ruff stops flagging them.

In `@tests/st/fuzz/src/orchestrator_generator.py`:
- Around line 35-39: The shape parameter is unused but must remain in the public
signature; to silence Ruff ARG002, consume it inside the function body (without
changing the parameter name) by assigning it to a throwaway variable—e.g. add a
line like _ = shape  # silence ruff ARG002—inside generate_sequential and the
other generator method that also accepts shape (the one around lines 109–113) so
the parameter is considered used while the signature stays intact.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7201a97 and 4fc6304.

📒 Files selected for processing (5)
  • tests/st/fuzz/README.md
  • tests/st/fuzz/src/fuzzer.py
  • tests/st/fuzz/src/kernel_generator.py
  • tests/st/fuzz/src/multi_kernel_test_generator.py
  • tests/st/fuzz/src/orchestrator_generator.py

@lwDavid
Copy link
Contributor Author

lwDavid commented Feb 24, 2026

@Hzfengsy Request review.

@Hzfengsy Hzfengsy merged commit d1dc1fe into hw-native-sys:main Feb 24, 2026
5 checks passed
@lwDavid lwDavid deleted the fix branch February 24, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants