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

Make default __format__ be equivalent to __str__ #73160

Closed
serhiy-storchaka opened this issue Dec 14, 2016 · 4 comments
Closed

Make default __format__ be equivalent to __str__ #73160

serhiy-storchaka opened this issue Dec 14, 2016 · 4 comments
Labels
3.7 interpreter-core type-feature

Comments

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Dec 14, 2016

BPO 28974
Nosy @rhettinger, @ericvsmith, @serhiy-storchaka
PRs
  • #506
  • Files
  • simpler-object-format.patch
  • 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 2017-05-13.09:41:23.437>
    created_at = <Date 2016-12-14.21:52:10.509>
    labels = ['interpreter-core', 'type-feature', '3.7']
    title = 'Make default __format__ be equivalent to __str__'
    updated_at = <Date 2017-05-13.09:41:23.436>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2017-05-13.09:41:23.436>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-05-13.09:41:23.437>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2016-12-14.21:52:10.509>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['45902']
    hgrepos = []
    issue_num = 28974
    keywords = ['patch']
    message_count = 4.0
    messages = ['283220', '293605', '293607', '293609']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'eric.smith', 'serhiy.storchaka']
    pr_nums = ['506']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue28974'
    versions = ['Python 3.7']

    @serhiy-storchaka
    Copy link
    Member Author

    @serhiy-storchaka serhiy-storchaka commented Dec 14, 2016

    Originally PEP-3101 defined the default __format__ implementation, object.__format__ as

         def __format__(self, format_spec):
             return format(str(self), format_spec)

    After few changes (bpo-7994, bpo-28385) it now looks as

         def __format__(self, format_spec):
             assert format_spec == ''
             return format(str(self), '')

    Proposed patch makes it yet simpler:

         def __format__(self, format_spec):
             assert format_spec == ''
             return str(self)

    This is equivalent to the previous form except obscure case when str() returns not exact str, but strict subclass with overridden __format__.

    The benefit of this change is simpler semantical model of the default implementation.

    See the start of the discussion in bpo-28385 and the discussion on Python-Dev: https://mail.python.org/pipermail/python-dev/2016-October/146765.html.

    @serhiy-storchaka serhiy-storchaka added 3.7 interpreter-core type-feature labels Dec 14, 2016
    @serhiy-storchaka
    Copy link
    Member Author

    @serhiy-storchaka serhiy-storchaka commented May 13, 2017

    What are your thoughts about this Eric?

    @ericvsmith
    Copy link
    Member

    @ericvsmith ericvsmith commented May 13, 2017

    I'm okay with this change.

    @serhiy-storchaka
    Copy link
    Member Author

    @serhiy-storchaka serhiy-storchaka commented May 13, 2017

    New changeset 7e19dbc by Serhiy Storchaka in branch 'master':
    bpo-28974: object.__format__(x, '') is now equivalent to str(x) (#506)
    7e19dbc

    @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.7 interpreter-core type-feature
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants