Skip to content

refactor(python)!: rename structure= to structural_eq=#509

Merged
junrushao merged 1 commit intoapache:mainfrom
junrushao:2026-03-22/rename-structure
Mar 23, 2026
Merged

refactor(python)!: rename structure= to structural_eq=#509
junrushao merged 1 commit intoapache:mainfrom
junrushao:2026-03-22/rename-structure

Conversation

@junrushao
Copy link
Member

@junrushao junrushao commented Mar 23, 2026

Summary

  • Rename the structure= parameter to structural_eq= in @py_class() and field() to better convey that the parameter controls structural equality/hashing behavior
  • Update Cython layer (type_info.pxi) to read the new attribute name
  • Update all tests and documentation to use the new parameter name

Breaking Change

The structure= parameter on @py_class() and field() has been renamed to structural_eq=.

Migration: replace all occurrences of structure= with structural_eq= in your @py_class() and field() calls:

# Before
@py_class(structure="tree")
class MyNode(Object):
    span: Object = field(structure="ignore")

# After
@py_class(structural_eq="tree")
class MyNode(Object):
    span: Object = field(structural_eq="ignore")

Test plan

  • uv pip install --force-reinstall --verbose -e . (full C++ rebuild required)
  • uv run pytest -vvs tests/python/test_structural_py_class.py
  • Verify all pre-commit hooks pass (confirmed locally: all passed)

🤖 Generated with Claude Code

Rename the `structure=` parameter to `structural_eq=` in both
`@py_class()` and `field()` to better communicate that the parameter
controls structural equality/hashing behavior, not general structure.

Affected APIs:
- `py_class(structure=...)` → `py_class(structural_eq=...)`
- `field(structure=...)` → `field(structural_eq=...)`

Files changed:
- python/tvm_ffi/dataclasses/field.py — Field class and field() function
- python/tvm_ffi/dataclasses/py_class.py — py_class() decorator
- python/tvm_ffi/cython/type_info.pxi — Cython getattr lookup
- tests/python/test_structural_py_class.py — all test annotations
- docs/concepts/structural_eq_hash.rst — tutorial documentation

BREAKING CHANGE: The `structure=` parameter on `@py_class()` and
`field()` has been renamed to `structural_eq=`. Update all call sites
to use the new parameter name.

Note: tests not run in this commit workflow — requires full C++ rebuild
via `uv pip install --force-reinstall --verbose -e .`.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 implements a significant refactoring by renaming the structure= parameter to structural_eq= across the Python and Cython layers. This change enhances clarity by providing a more descriptive name for the parameter that governs structural equality and hashing. The update ensures that the parameter's function is immediately understandable, improving code readability and maintainability for developers working with @py_class() and field() annotations.

Highlights

  • Parameter Renaming: The structure= parameter in @py_class() and field() has been renamed to structural_eq= to more accurately convey its role in controlling structural equality and hashing behavior.
  • Cython Layer Update: The underlying Cython implementation (type_info.pxi) was updated to correctly read the new structural_eq attribute.
  • Documentation and Test Migration: All relevant documentation and test cases have been updated to reflect the new structural_eq parameter name, ensuring consistency across the codebase.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

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.

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 renames the structure= parameter to structural_eq= in @py_class() and field(). This is a breaking change, and the description includes a migration guide. The rename has been applied consistently across documentation, Python source code, Cython bindings, and tests. The review did not identify any issues with the changes.

@junrushao junrushao merged commit 41d38fa into apache:main Mar 23, 2026
8 checks passed
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