Skip to content

Add note in docs regarding uppercase 'X' specifier #19332

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

Closed
wants to merge 1 commit into from
Closed

Add note in docs regarding uppercase 'X' specifier #19332

wants to merge 1 commit into from

Conversation

gotlibsh
Copy link

@gotlibsh gotlibsh commented Apr 3, 2020

I noticed that when using string format to print hexadecimal numbers like the following:

'{:#X}'.format(1234)
'0X4D2'

I get an uppercase 'X', this is worth mentioning in the docs.

I noticed that when using string format to print hexadecimal numbers like the following:

>>> '{:#X}'.format(1234)
'0X4D2'

I get an uppercase 'X', this is worth mentioning in the docs.
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@gotlibsh

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@taleinat
Copy link
Contributor

Hi, thanks for this! Definitely worth noting this in the docs.

Have you considered simply adding '0X' to the list in the paragraph describing the '#' modifier? I.e.:

The '#' option causes the “alternate form” to be used for the conversion. [...] For integers, when binary, octal, or hexadecimal output is used, this option adds the prefix respective '0b', '0o', '0x' or '0X' to the output value.

@gotlibsh
Copy link
Author

@taleinat Thanks for you input, I didn't consider this option.

On one hand it makes perfect sense to add it where you specified since it's a smaller and simpler change, but on the other hand, I am not sure it's the intuitive location that people will first look at when trying to understand this behavior.

How would you suggest to decide what the right solution is?

@taleinat
Copy link
Contributor

taleinat commented Sep 26, 2020

I prefer this in the description of the '#' modifier, since it is much more esoteric. Where possible, we should avoid having info about rare edge-cases mixed with info about common cases.

And as a core dev, if you make this change, I'd be happy to merge it :)

@orsenthil
Copy link
Member

I agree with @taleinat 's review.

+1 to adding a change here:

The '#' option causes the “alternate form” to be used for the conversion. [...] For integers, when binary, octal, or hexadecimal output is used, this option adds the prefix respective '0b', '0o', '0x' or '0X' to the output value.

If you keep the current patch that explains about upper casing of "0X" prefix along with rest. that's a good addition too. We don't want to give an impression that a format like "0xDEADBEEF" can be returned when using '{:#X}'.format("deadbeef")

@vstinner vstinner closed this May 3, 2021
@vstinner vstinner deleted the branch python:master May 3, 2021 21:29
@taleinat
Copy link
Contributor

taleinat commented May 6, 2021

Note that this was closed only due to the renaming of the master branch to main.

I still think that this is a worthy improvement to the docs, but can't re-open this PR due to the original branch having been deleted.

@orsenthil
Copy link
Member

Tal, we could cherry-pick this 12ec96e (I suppose) and create a new PR and merge it.

@taleinat
Copy link
Contributor

taleinat commented May 6, 2021

@orsenthil, I've already created a new PR for this, please see GH-25941.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants