You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Change object.__format__(s) where s is non-empty to a TypeError #54065
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=<Date2013-05-19.13:11:53.900>created_at=<Date2010-09-14.17:26:57.550>labels= ['interpreter-core', 'easy', 'deferred-blocker', 'type-bug']
title='Change object.__format__(s) where s is non-empty to a TypeError'updated_at=<Date2014-02-11.23:34:43.381>user='https://github.com/ericvsmith'
Perhaps this could be expanded to "Deprecation warnings in 3.3" with release-blocker priority to list all 3.2 PendingDWs. Once changes are made, it could be retitled "Removals in 3.4", with a new "Deprecation warnings in 3.4" added.
python-dev commented on Mar 12, 2011
python-devmannequin
Mannequin
More actions
New changeset ee259a4f3eee by Eric V. Smith in branch 'default': bpo-9856: Change object.__format__ with a non-empty format string from a PendingDeprecationWarning to a DeprecationWarning. http://hg.python.org/cpython/rev/ee259a4f3eee
changed the title [-]Change object.__format__(s) where s is non-empty to a DeprecationWarning[/-][+]Change object.__format__(s) where s is non-empty to a TypeError[/+]on Mar 12, 2011
The more I think about this, the more overly restrictive I realize it is. If the type of the object really is "object", then it can use string formatting. It's only for non-objects that I want to add the error.
@eric:
when you say: "If the type of the object really is "object", then it can use string formatting. It's only for non-objects that I want to add the error.".
I am confused. Let me demonstrate what I'm thinking according to the statement above.
First let us take a 'non-object':
>>> integer=1
>>> type(integer) !=object
True
As of now it returns the following:
>>> integer.__format__(s)
'1'
Which seems natural.
But after this patch should it return an error
Also now consider an object:
>>> f =object()
>>> type(f)
<class 'object'>
This will return the following after the patch as it does now which is:
>>> f.__format__('')
'<object object at 0xb75b7b48>'
Does this mean that 'integer' should give an error, however, 'f' should give something that appears messy?
I may be mistaken in my interpretation of the statement, so kindly let me know if there is something else that I am not clearly understanding.
YogeshChaudhari commented on May 12, 2013
YogeshChaudharimannequin
Mannequin
More actions
Please replace
integer.__format__(s)
with
integer.__format__('')
But int has its own __format__ method, so this does not apply. Per the title of this issue, this only refers to object.__format__.
For example:
This works now, and will continue working:
>>> format(2, '1')
'2'
This is currently an error, and will remain an error:
>>> classC: pass
...
>>> format(C(), '1')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: non-empty format string passed to object.__format__
It's this case that is currently an error, but it need not be:
>>> format(object(), '1')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: non-empty format string passed to object.__format__
The more I think about it, the more I think it would be too confusing to make object.__format__ behave differently if self is of type object, versus another type. So I'll probably just close this as fixed unless someone feels strongly about it.
YogeshChaudhari commented on May 12, 2013
YogeshChaudharimannequin
Mannequin
More actions
>It's this case that is currently an error, but it need not be:
>>>> format(object(), '1')
>Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
>TypeError: non-empty format string passed to object.__format__
I believe that should continue to remain an error. Please note that this works
>>> format(object(), '')
'<object object at 0xb74fd688>'
From what I can tell, specifying '1' or '2' or '100' makes no sense because unlike string or int (and like list or tuple ) this 'number' does not represent anything sensible.
This works fine as it should:
>>> format('q', '5')
'q '
>>> format(1, '5')
' 1'
>>> format(1, '05')
'00001'
>>>
But this does not and IMHO *should* not 'work'
>>> format([1,2,3], '5')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: non-empty format string passed to object.__format__
>>> format((1,2,3), '5')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: non-empty format string passed to object.__format__
an object() CANNOT have specific behavior like str or int. You can of-course argue as to what kind of error/exception/warning this may raise, but it does not make any sense (AFAIK) to 'fix' this.
Everying is an instance of object. If its class does not override .__format__, then it seems that it should act the same as a direct object instance. If this a the current plan (or patch already committed, I think I would stay with that.
YogeshChaudhari commented on May 13, 2013
YogeshChaudharimannequin
Mannequin
More actions
+1 to Terry for "If its class does not override .__format__, then it seems that it should act the same as a direct object instance"
Since Eric indicated he'd close this unless someone felt strongly that the status quo should be changed, and the arguments are in favor of *maintaining* the status quo, I'm going to close this for him :)
Activity
ericvsmith commentedon Sep 14, 2010
In 3.3 the existing PendingDeprecationWarning needs to become a DeprecationWarning. In 3.4 it will become an error.
I'll change 3.3 after 3.2 is released.
See bpo-7994 for the original PendingDeprecationWarning discussion.
terryjreedy commentedon Sep 18, 2010
Perhaps this could be expanded to "Deprecation warnings in 3.3" with release-blocker priority to list all 3.2 PendingDWs. Once changes are made, it could be retitled "Removals in 3.4", with a new "Deprecation warnings in 3.4" added.
python-dev commentedon Mar 12, 2011
New changeset ee259a4f3eee by Eric V. Smith in branch 'default':
bpo-9856: Change object.__format__ with a non-empty format string from a PendingDeprecationWarning to a DeprecationWarning.
http://hg.python.org/cpython/rev/ee259a4f3eee
ericvsmith commentedon Mar 12, 2011
Next step is to make it a TypeError in 3.4.
[-]Change object.__format__(s) where s is non-empty to a DeprecationWarning[/-][+]Change object.__format__(s) where s is non-empty to a TypeError[/+]florentx commentedon Dec 12, 2011
Patch is ready for python 3.4
:-)
krinart commentedon Dec 23, 2012
As I can see this is already implemented in 3.4
python-dev commentedon Dec 23, 2012
New changeset d91c14788729 by Andrew Svetlov in branch 'default':
Issue bpo-9856: Replace deprecation warinigs to raising TypeError in object.__format__
http://hg.python.org/cpython/rev/d91c14788729
3 remaining items
asvetlov commentedon Dec 23, 2012
Updated NEWS and docs
ericvsmith commentedon Dec 23, 2012
The more I think about this, the more overly restrictive I realize it is. If the type of the object really is "object", then it can use string formatting. It's only for non-objects that I want to add the error.
I'll re-open it and give it some more thought.
asvetlov commentedon Dec 23, 2012
Ok
YogeshChaudhari commentedon May 12, 2013
@eric:
when you say: "If the type of the object really is "object", then it can use string formatting. It's only for non-objects that I want to add the error.".
I am confused. Let me demonstrate what I'm thinking according to the statement above.
Does this mean that 'integer' should give an error, however, 'f' should give something that appears messy?
I may be mistaken in my interpretation of the statement, so kindly let me know if there is something else that I am not clearly understanding.
YogeshChaudhari commentedon May 12, 2013
Please replace
integer.__format__(s)
with
integer.__format__('')
ericvsmith commentedon May 12, 2013
But int has its own __format__ method, so this does not apply. Per the title of this issue, this only refers to object.__format__.
For example:
The more I think about it, the more I think it would be too confusing to make object.__format__ behave differently if self is of type object, versus another type. So I'll probably just close this as fixed unless someone feels strongly about it.
YogeshChaudhari commentedon May 12, 2013
From what I can tell, specifying '1' or '2' or '100' makes no sense because unlike string or int (and like list or tuple ) this 'number' does not represent anything sensible.
an object() CANNOT have specific behavior like str or int. You can of-course argue as to what kind of error/exception/warning this may raise, but it does not make any sense (AFAIK) to 'fix' this.
terryjreedy commentedon May 13, 2013
Everying is an instance of object. If its class does not override .__format__, then it seems that it should act the same as a direct object instance. If this a the current plan (or patch already committed, I think I would stay with that.
YogeshChaudhari commentedon May 13, 2013
+1 to Terry for "If its class does not override .__format__, then it seems that it should act the same as a direct object instance"
bitdancer commentedon May 19, 2013
Since Eric indicated he'd close this unless someone felt strongly that the status quo should be changed, and the arguments are in favor of *maintaining* the status quo, I'm going to close this for him :)
serhiy-storchaka commentedon Dec 2, 2013
Perhaps the versionchanged tag for format() is more suitable than versionadded.
python-dev commentedon Feb 11, 2014
New changeset f56b98143792 by R David Murray in branch 'default':
whatsnew: object.__format__ raises TypeError on non-empty string.
http://hg.python.org/cpython/rev/f56b98143792