Repository navigation
Conversation
This is a very convenient feature introduced in Python 3.6 by PEP 515.
Seems actually better than CPython to me: purpose is visual distinction so for long binary numbers this gives extra possibilities to distinguish the individual bytes etc, think 0b1111_1111__0000_0000 |
Nice idea! |
|
I merged support for underscore in literals in 6a445b6 For the string formatting using underscore: I didn't merge this because 1) it adds code size; 2) I don't know how useful it would be, how often it would be used; 3) the implementation was not correct because it put underscores every 3 digits for all bases, whereas CPython puts them every 4 digits for hex, oct and bin formats (supporting this behaviour would add even more code). |
This PR adds support for underscores in numeric literals, like
123_000and0b1011_0011_1010. This is added in Python 3.6 by PEP 515 and is quite useful (especially in the domain of microcontrollers) so I think it's worth adding, even if we don't yet fully support Python 3.5 syntax.To keep the code simple the patch allows through more possibilities than CPython, eg
123__456is allowed, and so is123_(they give errors in CPython). I don't see this as a problem.I also added support for formatting using
_; eg'{:10_}'.format(12345678)gives'12_345_678'. I don't know if this is really important to add, but it was short and simple to do just to see if it's worth adding.See #2415 for prior discussion on Python 3.6 support.