I disagree. As per the PEP’s abstract:
Both are presented together in this PEP as the alternative rejected implementations entail intertwined combinations of both.
If one is added without the other, and the other later is also to be added, but its implementation requires changing the first’s, it would be a mess at best and at worst a permanent incompatibility.
The whole point of the PEP, and many format specifiers in general, is so that this is done programmatically for the user.
?
The reduction of the integer into range(base ** precision) is intended and useful. Whether an underlying number formatted to "0xff" is -1 or 255 depends on what the user is programming, but in a machine-width oriented environment either integer is expected to print as "0xff". In other environments it’s an intended truncation / wrapping.
By two’s complement I mean what the number looks like if we try jamming it into a precision-bit register. Think of it as formatting the number with infinite length, unlimited preceding 0s for +ves, unlimited 1s for -ves, then truncating. Similarly for octal and hex. Yes two’s complement can only support a fixed number of bits in a fixed width register / C programming language, but Python’s integers are unlimited*, and we implement a sane extension.
The only deviation I can think of is that when using octal one can achieve 30 or 33 bits using precision 10 or 11 respectively, but not 32 bits, though I expect binary and hexadecimal to be the most common case invocation of z in machine-width oriented environments, and outside of that again works as intended.
>>> import os
>>> mode = os.stat("/bin/passwd").st_mode & 0o7777
>>> f"{mode:#.4o}" # full mode including setuid, setgid, sticky/temp
'0o4755'
>>> f"{mode:z#.3o}" # just the plain perms
'0o755'
Nope, it’s an intended feature
>>> key_id = 0xCC586D97DC421CB9A0ED6CA903D283F3F02C2660 # random int gpg key
>>> f"{key_id:z.8X}" # short
'F02C2660'
>>> f"{key_id:z.16X}" # long
'03D283F3F02C2660'
>>> f"{key_id:X}" # full
'CC586D97DC421CB9A0ED6CA903D283F3F02C2660'
To also quote the PEP
if a library sets a pixel brightness integer to be 257 […] that’s not our problem or doing […] let the appropriate ‘layer’ of code raise the exception
Your PR is not the intended behavior. It was also buggy.
Just lol. The PEP has already marinated for a year. This bickering is what led me to put this idea on hold for the year, even though it feels right.
You don’t understand the z flag’s purpose and you have very bad taste in wanting "0x080" when +128 is passed to f"{num:z#.2x}" and "0x80" when -128 is passed to it; that went into the rejected alternatives.
I’m looking more for the second opinions of other people in this thread at this point sorry. Not trying to be passive-aggressive it’s just pointless us butting heads lol.