This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Using format spec ',x' displays incorrect error message
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: FHTMitchell, Rosuav, eric.smith, nitishch, terry.reedy
Priority: normal Keywords: patch

Created on 2017-10-13 11:36 by FHTMitchell, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4002 merged pablogsal, 2017-10-15 02:35
PR 4004 merged python-dev, 2017-10-15 03:41
Messages (7)
msg304330 - (view) Author: FHTMitchell (FHTMitchell) Date: 2017-10-13 11:36
Minor issue. Using the ',b', ',o' or ',x' raises the error

ValueError("Cannot specify ',' or '_' with 'x'.",)

(or equivalently for 'b' and 'o'). However, it is possible to use the format specs '_b', '_o' and '_x' in Python 3.6 due to PEP 515. 

The following test demonstrates this:

>>> i = 10000
>>> for base in 'box':
...     for sep in ',_':
...         try:
...             print(f'{i:{sep}{base}}')
...         except ValueError as err:
...             print(repr(err))

ValueError("Cannot specify ',' or '_' with 'b'.",)
1_1000_0110_1010_0000
ValueError("Cannot specify ',' or '_' with 'o'.",)
30_3240
ValueError("Cannot specify ',' or '_' with 'x'.",)
1_86a0
msg304368 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-10-13 23:08
The formatting part of PEP 515 was implemented in #27080.  Chris Angelico's initial patch https://bugs.python.org/file44152/underscores_decimal_only.patch was, as the name says, for decimal only, and added "or '_' " to the error message.  The next patch added other bases but neglected to remove the obsoleted addition.

Chris, can you do a PR?  I don't think any new test is needed.  I would also be inclined to skip the news blurb, but since Eric should review and merge, it is his call.
msg304382 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-10-14 06:55
I agree there's no need for tests, since we usually don't guarantee such messages going forward. Also, I think skipping the news blurb is reasonable for this change.
msg304412 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-10-15 03:41
New changeset 28773ca7a7aa58a28e42a9eb0066acf71b5a8dc4 by Terry Jan Reedy (Dargor) in branch 'master':
bpo-31780: Fix incorrect error message for ',x', ',b', ',o' specs (#4002)
https://github.com/python/cpython/commit/28773ca7a7aa58a28e42a9eb0066acf71b5a8dc4
msg304413 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-10-15 04:01
New changeset 59b5c139d2ae95b1d1da63f81c3d777932215533 by Terry Jan Reedy (Miss Islington (bot)) in branch '3.6':
[3.6] bpo-31780: Fix incorrect error message for ',x', ',b', ',o' specs (GH-4002) (#4004)
https://github.com/python/cpython/commit/59b5c139d2ae95b1d1da63f81c3d777932215533
msg304547 - (view) Author: Chris Angelico (Rosuav) * Date: 2017-10-18 00:38
Thanks for handling that Terry. I take it the PR isn't needed now?

I would have done it, but I'm on the way to the US (literally posting this from the airport), and hadn't gotten to looking at this in the interval.
msg304558 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-10-18 07:58
Correct.  Fixed.
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 75961
2017-10-18 07:58:16terry.reedysetmessages: + msg304558
2017-10-18 00:38:16Rosuavsetmessages: + msg304547
2017-10-15 04:01:57terry.reedysetstatus: open -> closed
assignee: terry.reedy
resolution: fixed
stage: patch review -> resolved
2017-10-15 04:01:30terry.reedysetmessages: + msg304413
2017-10-15 03:41:28python-devsetpull_requests: + pull_request3977
2017-10-15 03:41:16terry.reedysetmessages: + msg304412
2017-10-15 02:35:19pablogsalsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request3975
2017-10-14 23:31:29nitishchsetnosy: + nitishch
2017-10-14 06:55:09eric.smithsetmessages: + msg304382
2017-10-13 23:08:21terry.reedysetversions: + Python 3.7
nosy: + Rosuav, terry.reedy

messages: + msg304368

components: + Interpreter Core
stage: needs patch
2017-10-13 15:59:43ned.deilysetnosy: + eric.smith
2017-10-13 11:36:55FHTMitchellcreate