Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trait ergonomics str implementation (#4233)
* feat: Implement custom string formatting for PyClass This update brings custom string formatting for PyClass with a #[pyclass(str = "format string")] attribute. It allows users to specify how their PyClass objects are converted to string in Python. The implementation includes additional tests and parsing logic. * update: removed debug print statements * update: added members to ToTokens implementation. * update: reverted to display * update: initial tests * update: made STR public for pyclass default implementations * update: generalizing str implementation * update: remove redundant test * update: implemented compile test to validate that manually implemented str is not allowed when automated str is requested * update: updated compile time error check * update: rename test file and code cleanup * update: format cleanup * update: added news fragment * fix: corrected clippy findings * update: fixed mixed formatting case and improved test coverage * update: improved test coverage * refactor: generalized formatting function to accommodate __repr__ in a future implementation since it will use the same shorthand formatting logic * update: Add support for rename formatting in PyEnum3 Implemented the capacity to handle renamed variants in enum string representation. Now, custom Python names for enum variants will be correctly reflected when calling the __str__() method on an enum instance. Additionally, the related test has been updated to reflect this change. * fix: fixed clippy finding * update: fixed test function names * Update pyo3-macros-backend/src/pyclass.rs Co-authored-by: Bruno Kolenbrander <[email protected]> * Update newsfragments/4233.added.md Co-authored-by: Bruno Kolenbrander <[email protected]> * update: implemented hygienic calls and added hygiene tests. * update: cargo fmt * update: retained LitStr usage in the quote in order to preserve a more targeted span for the format string. * update: retained LitStr usage in the quote in order to preserve a more targeted span for the format string. * update: added compile time error check for invalid fields (looking to reduce span of invalid member) * update: implemented a subspan to improve errors in format string on nightly, verified additional test cases on both nightly and stable * update: updated test output * update: updated with clippy findings * update: added doc entries. * update: corrected error output for compile errors after updating from main. * update: added support for raw identifiers used in field names * update: aligning branch with main * update: added compile time error when mixing rename_all or name pyclass, field, or variant args when mixed with a str shorthand formatter. * update: removed self option from str format shorthand, restricted str shorthand format to structs only, updated docs with changes, refactored renaming incompatibility check with str shorthand. * update: removed checks for shorthand and renaming for enums and simplified back to inline check for structs * update: added additional test case to increase coverage in match branch * fix: updated pyclass heighten check to validate for eq and ord, fixing Ok issue in eq implementation. * Revert "fix: updated pyclass heighten check to validate for eq and ord, fixing Ok issue in eq implementation." This reverts commit a37c24b. * update: improved error comments, naming, and added reference to the PR for additional details regarding the implementation of `str` * update: fixed merge conflict --------- Co-authored-by: Michael Gilbert <[email protected]> Co-authored-by: Bruno Kolenbrander <[email protected]> Co-authored-by: MG <[email protected]>
- Loading branch information