Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error messages in str.format() #72333

Closed
serhiy-storchaka opened this issue Sep 14, 2016 · 7 comments
Closed

Confusing error messages in str.format() #72333

serhiy-storchaka opened this issue Sep 14, 2016 · 7 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-unicode type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 28146
Nosy @pitrou, @vstinner, @ericvsmith, @ezio-melotti, @serhiy-storchaka, @miss-islington, @iritkatriel
PRs
  • bpo-28146: Fix a confusing error message in str.format() #24213
  • [3.8] bpo-28146: Fix a confusing error message in str.format() (GH-24213) #26110
  • [3.9] bpo-28146: Fix a confusing error message in str.format() (GH-24213) #26111
  • [3.10] bpo-28146: Fix a confusing error message in str.format() (GH-24213) #26112
  • 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 = None
    closed_at = <Date 2021-05-13.21:39:16.746>
    created_at = <Date 2016-09-14.11:12:35.529>
    labels = ['interpreter-core', 'type-bug', '3.9', '3.10', '3.11', 'expert-unicode']
    title = 'Confusing error messages in str.format()'
    updated_at = <Date 2021-05-14.08:08:15.534>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2021-05-14.08:08:15.534>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-05-13.21:39:16.746>
    closer = 'pitrou'
    components = ['Interpreter Core', 'Unicode']
    creation = <Date 2016-09-14.11:12:35.529>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 28146
    keywords = ['patch']
    message_count = 7.0
    messages = ['276415', '276417', '385052', '393608', '393610', '393612', '393631']
    nosy_count = 7.0
    nosy_names = ['pitrou', 'vstinner', 'eric.smith', 'ezio.melotti', 'serhiy.storchaka', 'miss-islington', 'iritkatriel']
    pr_nums = ['24213', '26110', '26111', '26112']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28146'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @serhiy-storchaka
    Copy link
    Member Author

    For example:

    >>> '{:04}'.format('abc')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: '=' alignment not allowed in string format specifier

    There is no any '=' in the format string.

    >>> '{: }'.format('abc')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: Sign not allowed in string format specifier

    There is no any sign ('+' or '-') in the format string.

    There also an inconsistency between the wording of "something not allowed in string format specifier" and:

    >>> '{:x}'.format('abc')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: Unknown format code 'x' for object of type 'str'
    >>> '{:xx}'.format('abc')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: Invalid format specifier

    @serhiy-storchaka serhiy-storchaka added interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-unicode labels Sep 14, 2016
    @serhiy-storchaka serhiy-storchaka changed the title Confusing error examples in str.format() Confusing error messages in str.format() Sep 14, 2016
    @ericvsmith
    Copy link
    Member

    See also bpo-27772.

    The difference in the error messages is due to the first ones looking for specific invalid combinations (in this case things the string formatter does not understand), and the last one which is "I have no idea what you're asking for".

    @ericvsmith ericvsmith added the type-bug An unexpected behavior, bug, or error label Sep 14, 2016
    @iritkatriel
    Copy link
    Member

    My PR fixes the second case ('{: }') and Serhiy's PR on bpo-27772 fixes the first case ('{:04}').

    @pitrou pitrou added the 3.11 only security fixes label May 13, 2021
    @miss-islington
    Copy link
    Contributor

    New changeset 2d78023 by Miss Islington (bot) in branch '3.10':
    bpo-28146: Fix a confusing error message in str.format() (GH-24213)
    2d78023

    @miss-islington
    Copy link
    Contributor

    New changeset 133013e by Miss Islington (bot) in branch '3.9':
    bpo-28146: Fix a confusing error message in str.format() (GH-24213)
    133013e

    @pitrou
    Copy link
    Member

    pitrou commented May 13, 2021

    It seems like this issue is entirely fixed now, closing.

    @pitrou pitrou added 3.9 only security fixes 3.10 only security fixes labels May 13, 2021
    @pitrou pitrou closed this as completed May 13, 2021
    @vstinner
    Copy link
    Member

    commit 4aeee0b
    Author: Irit Katriel <iritkatriel@yahoo.com>
    Date: Thu May 13 21:55:55 2021 +0100

    bpo-28146: Fix a confusing error message in str.format() (GH-24213)
    
    
    
    Automerge-Triggered-By: GH:pitrou
    

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-unicode type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    6 participants