Skip to content

Using format spec ',x' displays incorrect error message #75961

Closed

Description

@FHTMitchell
BPO 31780
Nosy @terryjreedy, @ericvsmith, @Rosuav, @nitishch, @FHTMitchell
PRs
  • bpo-31780: Fix incorrect message for format spec #4002
  • [3.6] bpo-31780: Fix incorrect error message for ',x', ',b', ',o' specs (GH-4002) #4004
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/terryjreedy'
    closed_at = <Date 2017-10-15.04:01:57.698>
    created_at = <Date 2017-10-13.11:36:55.930>
    labels = ['interpreter-core', 'type-bug', '3.7']
    title = "Using format spec ',x' displays incorrect error message"
    updated_at = <Date 2017-10-18.07:58:16.456>
    user = 'https://github.com/FHTMitchell'

    bugs.python.org fields:

    activity = <Date 2017-10-18.07:58:16.456>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2017-10-15.04:01:57.698>
    closer = 'terry.reedy'
    components = ['Interpreter Core']
    creation = <Date 2017-10-13.11:36:55.930>
    creator = 'FHTMitchell'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31780
    keywords = ['patch']
    message_count = 7.0
    messages = ['304330', '304368', '304382', '304412', '304413', '304547', '304558']
    nosy_count = 5.0
    nosy_names = ['terry.reedy', 'eric.smith', 'Rosuav', 'nitishch', 'FHTMitchell']
    pr_nums = ['4002', '4004']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue31780'
    versions = ['Python 3.6', 'Python 3.7']

    Activity

    1. FHTMitchell commented on Oct 13, 2017

      FHTMitchellmannequin
      MannequinAuthor

      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
    2. added
      type-bug
      on Oct 13, 2017
    3. terryjreedy commented on Oct 13, 2017

      @terryjreedy
      Member

      The formatting part of PEP-515 was implemented in bpo-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.

    4. added
      interpreter-core
      3.7 (EOL)
      on Oct 13, 2017
    5. ericvsmith commented on Oct 14, 2017

      @ericvsmith
      Member

      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.

    6. terryjreedy commented on Oct 15, 2017

      @terryjreedy
      Member

      New changeset 28773ca by Terry Jan Reedy (Dargor) in branch 'master':
      bpo-31780: Fix incorrect error message for ',x', ',b', ',o' specs (bpo-4002)
      28773ca

    7. terryjreedy commented on Oct 15, 2017

      @terryjreedy
      Member

      New changeset 59b5c13 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) (bpo-4004)
      59b5c13

    8. self-assigned this
      on Oct 15, 2017
    9. Rosuav commented on Oct 18, 2017

      @Rosuav
      Contributor

      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.

    10. terryjreedy commented on Oct 18, 2017

      @terryjreedy
      Member

      Correct. Fixed.

    11. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.7 (EOL)interpreter-coretype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions