Issue 31780: Using format spec ',x' displays incorrect error message (original) (raw)

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

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:53

admin

set

github: 75961

2017-10-18 07:58:16

terry.reedy

set

messages: +

2017-10-18 00:38:16

Rosuav

set

messages: +

2017-10-15 04:01:57

terry.reedy

set

status: open -> closed
assignee: terry.reedy
resolution: fixed
stage: patch review -> resolved

2017-10-15 04:01:30

terry.reedy

set

messages: +

2017-10-15 03:41:28

python-dev

set

pull_requests: + <pull%5Frequest3977>

2017-10-15 03:41:16

terry.reedy

set

messages: +

2017-10-15 02:35:19

pablogsal

set

keywords: + patch
stage: needs patch -> patch review
pull_requests: + <pull%5Frequest3975>

2017-10-14 23:31:29

nitishch

set

nosy: + nitishch

2017-10-14 06:55:09

eric.smith

set

messages: +

2017-10-13 23:08:21

terry.reedy

set

versions: + Python 3.7
nosy: + Rosuav, terry.reedy

messages: +

components: + Interpreter Core
stage: needs patch

2017-10-13 15:59:43

ned.deily

set

nosy: + eric.smith

2017-10-13 11:36:55

FHTMitchell

create