gemini-code-assist[bot] commented on PR #491:
URL: https://github.com/apache/tvm-ffi/pull/491#issuecomment-3980958906
## Summary of Changes
Hello, I'm Gemini Code Assist[^1]! 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 significantly enhances the Python FFI (Foreign Function
Interface) by automating the generation and wiring of `__init__` methods for
C++-backed Python objects. By leveraging C++ reflection metadata, the system
now produces accurate `__init__` signatures and automatically integrates them
into registered Python classes, simplifying object instantiation and improving
type checking. This change streamlines the development experience for users
interacting with C++ objects in Python.
### Highlights
* **Automated __init__ Signature Generation**: The Python stubgen tool has
been extended to automatically emit correct `__init__` signatures for classes
derived from C++ reflection metadata. This includes handling KWARGS-protocol
`__init__` stubs (`_gen_auto_init`) and positional pass-through from
`__c_ffi_init__` (`_gen_c_init`).
* **Automatic __init__ Wiring for Registered Objects**: The
`register_object` decorator now automatically installs an `__init__` method for
registered classes if their C++ type has `refl::init()` metadata. This
eliminates the need for the `@c_class` decorator to provide `__init__`
functionality for C++ constructors.
* **Improved Type Hinting and Compatibility**: Many `ty:
ignore[too-many-positional-arguments]` comments have been removed from test
files, indicating that the generated `__init__` signatures now correctly match
the expected arguments. The `_install_init` function in `registry.py` has been
refined to preserve backward compatibility for base classes without
`__ffi_init__`.
* **Updated Documentation for __slots__**: Docstrings for `Object` and
`register_object` have been updated to recommend `__slots__ = ("__dict__",)`
for enabling per-instance dictionaries, replacing the previously suggested
`slots=False` metaclass keyword.
🧠**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](https://codeassist.google/code-review/login) to enable Memory in your
admin console.**
<details>
<summary><b>Changelog</b></summary>
* **examples/python_packaging/python/my_ffi_extension/_ffi_api.py**
* Added `__init__` type hint for `IntPair` within a `TYPE_CHECKING`
block.
* **examples/python_packaging/run_example.py**
* Updated `IntPair` instantiation with a type ignore comment.
* **python/tvm_ffi/cython/object.pxi**
* Updated `Object` class docstring to clarify `__slots__` usage.
* **python/tvm_ffi/dataclasses/__init__.py**
* Updated module docstring to reflect structural comparison and hashing.
* **python/tvm_ffi/registry.py**
* Added documentation for `__slots__` usage in `register_object`.
* Integrated `_install_init` call into the `_register` function.
* Enhanced docstring for `_make_init` to detail signature generation.
* Enhanced docstring for `_make_init_signature` to describe parent chain
traversal.
* Refactored `_install_init` to streamline logic and error handling.
* **python/tvm_ffi/structural.py**
* Added `__init__` and `__c_ffi_init__` type hints for `StructuralKey`.
* **python/tvm_ffi/stub/codegen.py**
* Updated `generate_object` to conditionally import `TYPE_CHECKING`
based on `init_lines`.
* Included generated `__init__` stub lines in the `TYPE_CHECKING` block.
* **python/tvm_ffi/stub/utils.py**
* Introduced `_parse_type_schema` for flexible type schema parsing.
* Defined `InitFieldInfo` dataclass to store `__init__` field details.
* Extended `ObjectInfo` with `__init__` related fields and updated
schema parsing.
* Implemented methods in `ObjectInfo` to generate `__init__` stubs based
on reflection.
* **python/tvm_ffi/testing/testing.py**
* Added `__init__` and `__c_ffi_init__` type hints for `TestObjectBase`.
* Added `__init__` type hint for `TestIntPair`.
* Added `__init__` and `__c_ffi_init__` type hints for
`TestObjectDerived`.
* Added `__init__` and `__c_ffi_init__` type hints and removed `value`
field from `TestNonCopyable`.
* Reordered and added `__init__` and `__c_ffi_init__` type hints for
several testing classes.
* Added `__ffi_shallow_copy__` and `__c_ffi_init__` type hints for
`_TestCxxClassDerived`.
* Added `__ffi_shallow_copy__` and `__c_ffi_init__` type hints for
`_TestCxxClassDerivedDerived`.
* Added `__ffi_shallow_copy__` and `__c_ffi_init__` type hints for
`_TestCxxInitSubset`.
* Added `__ffi_shallow_copy__` and `__c_ffi_init__` type hints for
`_TestCxxKwOnly`.
* Added `__ffi_shallow_copy__` and `__c_ffi_init__` type hints for
`_TestCxxAutoInitKwOnlyDefaults`.
* Added `__ffi_shallow_copy__` type hint for `_TestCxxNoAutoInit`.
* Added `__ffi_shallow_copy__` and `__c_ffi_init__` type hints for
`_TestCxxAutoInitParent`.
* Added `__ffi_shallow_copy__` and `__c_ffi_init__` type hints for
`_TestCxxAutoInitChild`.
* **tests/python/test_dataclass_compare.py**
* Removed `too-many-positional-arguments` type ignore comments and
updated object instantiations.
* **tests/python/test_dataclass_copy.py**
* Removed `too-many-positional-arguments` type ignore comments and
`unresolved-attribute` type ignore comments.
* Updated comment for deep copy branch coverage.
* **tests/python/test_dataclass_hash.py**
* Removed `too-many-positional-arguments` type ignore comments and
updated object instantiations.
* **tests/python/test_dataclass_repr.py**
* Updated object instantiations to use keyword arguments.
* **tests/python/test_object.py**
* Added a test case for `TestObjectBase` with auto-generated
`__ffi_init__`.
* Removed `too-many-positional-arguments` type ignore comment from
`TestIntPair` instantiation.
</details>
<details>
<summary><b>Using Gemini Code Assist</b></summary>
<br>
The full guide for Gemini Code Assist can be found on our [documentation
page](https://developers.google.com/gemini-code-assist/docs/review-github-code),
here are some quick tips.
<b>Invoking Gemini</b>
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.
<b>Customization</b>
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](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
<b>Limitations & Feedback</b>
Gemini Code Assist may make mistakes. Please leave feedback on any instances
where its feedback is incorrect or counter productive. You can react with
:thumbsup: and :thumbsdown: 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](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
<b>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](https://cloud.google.com/products/gemini/code-assist).</b>
</details>
[^1]: Review the [Privacy Notices](https://policies.google.com/privacy),
[Generative AI Prohibited Use
Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of
Service](https://policies.google.com/terms), and learn how to configure Gemini
Code Assist in GitHub
[here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
Gemini can make mistakes, so double check it and [use code with
caution](https://support.google.com/legal/answer/13505487).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]