-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Reading the code, when I saw the commend saying All letters used in the representation are normalized to lowercase, I thought it also refers to hex letters. However, a few lines later, I was disappointed to see Change hex literals to upper case..
Lines 5158 to 5168 in 6284953
| All letters used in the representation are normalized to lowercase (except | |
| in Python 2 long literals). | |
| """ | |
| text = leaf.value.lower() | |
| if text.startswith(("0o", "0b")): | |
| # Leave octal and binary literals alone. | |
| pass | |
| elif text.startswith("0x"): | |
| # Change hex literals to upper case. | |
| before, after = text[:2], text[2:] | |
| text = f"{before}{after.upper()}" |
There's one practical issue with use of upper-case hex letters, though, and that's similarity between letter B and digit 8.
I have seen bugs caused by this similarity in security-sensitive code, such as UTF-8/-16 decoders. Personally, I always used uppercase letters in hex numerals prior to that incident, because of the aesthetics of it; but, since then, have been switching to lowercase anywhere possible.
Maybe Black would consider switching to lowercase hex letters, as well?