gemini-code-assist[bot] commented on PR #94:
URL: https://github.com/apache/tvm-ffi/pull/94#issuecomment-3379289475
## Summary of Changes
This pull request enhances the `TypeSchema` class by introducing a flexible
`repr` method. This new API allows developers to provide a custom mapping
function (`ty_map`) to control how type names are rendered in string
representations, enabling scenarios like transforming `list` to `Sequence` or
`dict` to `Mapping`. This change improves the adaptability of schema generation
and type display for downstream applications.
### Highlights
* **Flexible Type Representation**: Introduced a new
`TypeSchema.repr(ty_map)` method that allows for customizable string
representation of type schemas. This enables downstream applications to
override how type names (e.g., `list`, `dict`) are displayed.
* **TypeSchema Dataclass Modification**: The `TypeSchema` dataclass was
modified by removing `frozen=True`, allowing for potential future modifications
to instances.
* **Default Type Arguments**: Updated the `TypeSchema` constructor to
automatically assign `TypeSchema("Any")` as default arguments for empty `list`
and `dict` types during initialization.
* **Refactored __repr__**: The `TypeSchema.__repr__` method was refactored
to delegate its functionality to the new `repr` method, ensuring consistent and
customizable string output.
* **Expanded FFI Testing**: Added new C++ FFI functions and corresponding
Python tests for generic `ArrayObj` and `MapObj` types, including verification
of the new `repr` functionality with custom type mappings.
<details>
<summary><b>Changelog</b></summary>
* **python/tvm_ffi/core.pyi**
* Added `TypeSchema.repr` method signature with an optional `ty_map`
callable.
* **python/tvm_ffi/cython/type_info.pxi**
* Removed `frozen=True` from the `TypeSchema` dataclass decorator.
* Modified the `TypeSchema` constructor to default `list` and `dict`
arguments to `TypeSchema("Any")` when no arguments are provided.
* Refactored `TypeSchema.__repr__` to call the new `repr` method.
* Implemented the `TypeSchema.repr` method, which handles custom type
mapping and various type origins (Union, Optional, Callable, etc.).
* **src/ffi/extra/testing.cc**
* Added new FFI functions `testing.schema_id_arr` and
`testing.schema_id_map` for `ArrayObj` and `MapObj` respectively, to expand
testing coverage.
* **tests/cpp/test_metadata.cc**
* Added `EXPECT_EQ` assertions to verify the JSON schema for the newly
added `testing.schema_id_arr` and `testing.schema_id_map` functions.
* **tests/python/test_metadata.py**
* Introduced a helper function `_replace_list_dict` to demonstrate the
`ty_map` functionality.
* Added new test cases for `testing.schema_id_arr` and
`testing.schema_id_map` to `test_schema_global_func`.
* Extended existing tests (`test_schema_global_func`,
`test_schema_field`, `test_schema_member_method`) to include assertions for the
new `repr` method with the `_replace_list_dict` mapping.
</details>
<details>
<summary><b>Activity</b></summary>
* The author, junrushao, requested a summary of the pull request.
* The author, junrushao, requested a review of the pull request.
</details>
--
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]