Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python __repr__ #320

Merged
merged 1 commit into from
Nov 27, 2023
Merged

Python __repr__ #320

merged 1 commit into from
Nov 27, 2023

Conversation

arvidn
Copy link
Contributor

@arvidn arvidn commented Nov 23, 2023

cleanup repr and str in python binding to make all streamable types have a __repr__() based on the rust Debug trait. The BLS types also have a separate __str__().

The main objective with this is to make sure rust types have reasonable __repr__ implementations.

currently we get this:

>>> import chia_rs
>>> chia_rs.Coin(b"1" * 32, b"2" * 32, 1234)
<builtins.Coin object at 0x10051e070>

With this patch, we get this:

>>> import chia_rs
>>> chia_rs.Coin(b"1" * 32, b"2" * 32, 1234)
Coin { parent_coin_info: 3131313131313131313131313131313131313131313131313131313131313131, puzzle_hash: 3232323232323232323232323232323232323232323232323232323232323232, amount: 1234 }

The chia-bls types are special, because they need to be compatible with blspy so they have special handling and distinguish between Display (__str__) and Debug (__repr__).

@arvidn arvidn force-pushed the python-repr branch 2 times, most recently from 52d444a to a1a9126 Compare November 23, 2023 15:29
Copy link

coveralls-official bot commented Nov 23, 2023

Pull Request Test Coverage Report for Build 6985078608

  • 36 of 40 (90.0%) changed or added relevant lines in 6 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.02%) to 85.809%

Changes Missing Coverage Covered Lines Changed/Added Lines %
chia-protocol/src/coin.rs 0 1 0.0%
chia-bls/src/secret_key.rs 5 8 62.5%
Files with Coverage Reduction New Missed Lines %
chia-bls/src/secret_key.rs 1 95.76%
Totals Coverage Status
Change from base Build 6984633742: -0.02%
Covered Lines: 9995
Relevant Lines: 11648

💛 - Coveralls

… types have a __repr__() based on the rust Debug trait. The BLS types also have a separate __str__()
@arvidn arvidn marked this pull request as ready for review November 24, 2023 21:57
@arvidn arvidn requested a review from AmineKhaldi November 27, 2023 12:46
@cmmarslender cmmarslender merged commit 094a2e4 into main Nov 27, 2023
52 checks passed
@cmmarslender cmmarslender deleted the python-repr branch November 27, 2023 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants