Skip to content

bpo-45155 : Default arguments for int.to_bytes(length=1, byteorder=sys.byteorder) #28265

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

Merged
merged 19 commits into from
Sep 16, 2021

Conversation

warsaw
Copy link
Member

@warsaw warsaw commented Sep 9, 2021

In the PEP 467 discussion, I proposed being able to use

>>> (65).to_bytes()
b'A'

IOW, adding default arguments for the length and byteorder arguments to int.to_bytes()

It occurs to me that this is (1) useful on its own merits; (2) easy to do. So I've done it.

https://bugs.python.org/issue45155

@rhettinger
Copy link
Contributor

This is a nice improvement. Thanks.

Copy link
Member

@ericvsmith ericvsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks reasonable to me. But .format() instead of f-strings? What?!

@rhettinger
Copy link
Contributor

@warsaw
Copy link
Member Author

warsaw commented Sep 9, 2021

This all looks reasonable to me. But .format() instead of f-strings? What?!

Ha! I knew you'd say that 😆
I wanted to minimally edit the line so it would fit within my editor line length. That looked like some Python 2.6 code to me!

The main docs need to be updated as well: https://docs.python.org/3/library/stdtypes.html?highlight=to_bytes#int.to_bytes

Yep, thanks @rhettinger ... coming up!

@rhettinger
Copy link
Contributor

Also consider updating the default byteorder for int.from_bytes. The to/from round trip should be as symmetrical as possible.

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beat me to it! I agree that int.from_bytes deserves the same treatment, too.

I also saw one possible improvement:

@encukou
Copy link
Member

encukou commented Sep 10, 2021

Please, for the sake of reproducible science (and other cases), don't add platform-dependent defaults.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@warsaw
Copy link
Member Author

warsaw commented Sep 10, 2021

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@brandtbucher: please review the changes made to this pull request.

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just one RST nit:

@warsaw warsaw requested a review from brandtbucher September 15, 2021 04:50
@warsaw
Copy link
Member Author

warsaw commented Sep 15, 2021

"big" by default.

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed some!

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@warsaw
Copy link
Member Author

warsaw commented Sep 15, 2021

Thanks for catching the ones I missed @brandtbucher

@warsaw
Copy link
Member Author

warsaw commented Sep 15, 2021

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@brandtbucher: please review the changes made to this pull request.

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I promise this is my last review!

Just realized that we can help AC give us a better __text_signature__ (for help, inspect, etc.). Other than that improvement, this looks good!

warsaw and others added 2 commits September 15, 2021 13:28
Co-authored-by: Brandt Bucher <[email protected]>
Co-authored-by: Brandt Bucher <[email protected]>
@brandtbucher
Copy link
Member

(I think you need to re-run AC locally, too.)

@warsaw warsaw merged commit 07e737d into python:main Sep 16, 2021
@bedevere-bot
Copy link

@warsaw: Please replace # with GH- in the commit message next time. Thanks!

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.

8 participants