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

',' formatting with empty format type '' (PEP 378) #50032

Closed
ericvsmith opened this issue Apr 17, 2009 · 5 comments
Closed

',' formatting with empty format type '' (PEP 378) #50032

ericvsmith opened this issue Apr 17, 2009 · 5 comments
Assignees
Labels
easy interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ericvsmith
Copy link
Member

BPO 5782
Nosy @rhettinger, @mdickinson, @ericvsmith

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/ericvsmith'
closed_at = <Date 2009-04-22.17:04:47.678>
created_at = <Date 2009-04-17.14:38:02.690>
labels = ['interpreter-core', 'easy', 'type-bug']
title = "',' formatting with empty format type '' (PEP 378)"
updated_at = <Date 2009-04-22.17:04:47.656>
user = 'https://github.com/ericvsmith'

bugs.python.org fields:

activity = <Date 2009-04-22.17:04:47.656>
actor = 'eric.smith'
assignee = 'eric.smith'
closed = True
closed_date = <Date 2009-04-22.17:04:47.678>
closer = 'eric.smith'
components = ['Interpreter Core']
creation = <Date 2009-04-17.14:38:02.690>
creator = 'eric.smith'
dependencies = []
files = []
hgrepos = []
issue_num = 5782
keywords = ['easy']
message_count = 5.0
messages = ['86075', '86079', '86080', '86081', '86306']
nosy_count = 3.0
nosy_names = ['rhettinger', 'mark.dickinson', 'eric.smith']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue5782'
versions = ['Python 3.1', 'Python 2.7']

@ericvsmith
Copy link
Member Author

PEP-378 says that the ',' format option applies to types 'd', 'e', 'f',
'g', 'E', 'G', '%' and 'F'. I think this should also be extended to
include the empty type ''.

This only makes a difference for floats. For ints, '' is the same as
'd', but for floats '' is distinct. In 3.1 we get this behavior:

>>> format(1.2, '010.2')
'00000001.2'
>>> format(1.2, '010,.2')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Cannot specify ',' with ''.

I think the second example should be valid.

@ericvsmith ericvsmith self-assigned this Apr 17, 2009
@ericvsmith ericvsmith added interpreter-core (Objects, Python, Grammar, and Parser dirs) easy type-bug An unexpected behavior, bug, or error labels Apr 17, 2009
@rhettinger
Copy link
Contributor

I concur.

@mdickinson
Copy link
Member

Sounds good to me, too.

It looks as though the Decimal type already does this:

Python 3.1a2+ (py3k:71669:71684M, Apr 17 2009, 19:23:53) 
[GCC 4.0.1 (Apple Inc. build 5490)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import Decimal
>>> format(Decimal('1.2'), '010.2')
'00000001.2'
>>> format(Decimal('1.2'), '010,.2')
'0,000,001.2'

@ericvsmith
Copy link
Member Author

I updated the PEP in r71686. I'll fix the code and add a test after I
backport the entire thing to 2.7.

@ericvsmith
Copy link
Member Author

Checked in to trunk in r71802 and py3k in r71804.

@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
easy interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants