Issue 9856: Change object.format(s) where s is non-empty to a TypeError (original) (raw)

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: Ankur.Ankan, Arfrever, Yogesh.Chaudhari, asvetlov, eric.smith, flox, krinart, python-dev, r.david.murray, serhiy.storchaka, terry.reedy
Priority: deferred blocker Keywords: easy, patch

Created on 2010-09-14 17:26 by eric.smith, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue9856_python-3.4.diff flox,2011-12-12 19:55 review
Messages (21)
msg116413 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-09-14 17:26
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 issue 7994 for the original PendingDeprecationWarning discussion.
msg116751 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-09-18 03:23
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.
msg130681 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-12 15:09
New changeset ee259a4f3eee by Eric V. Smith in branch 'default': Issue 9856: Change object.__format__ with a non-empty format string from a PendingDeprecationWarning to a DeprecationWarning. http://hg.python.org/cpython/rev/ee259a4f3eee
msg130682 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2011-03-12 15:14
Next step is to make it a TypeError in 3.4.
msg149351 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011-12-12 19:55
Patch is ready for python 3.4 :-)
msg177970 - (view) Author: Viktor Ershov (krinart) * Date: 2012-12-23 10:28
As I can see this is already implemented in 3.4
msg177977 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-12-23 12:27
New changeset d91c14788729 by Andrew Svetlov in branch 'default': Issue #9856: Replace deprecation warinigs to raising TypeError in object.__format__ http://hg.python.org/cpython/rev/d91c14788729
msg177981 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-12-23 12:42
Committed. Thanks.
msg177983 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-12-23 13:12
New changeset 2f6ec67636b8 by Andrew Svetlov in branch 'default': Add NEWS and docs for #9856 http://hg.python.org/cpython/rev/2f6ec67636b8
msg177984 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-12-23 13:19
Updated NEWS and docs
msg177992 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2012-12-23 16:19
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.
msg177994 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-12-23 16:28
Ok
msg189048 - (view) Author: Yogesh Chaudhari (Yogesh.Chaudhari) * Date: 2013-05-12 17:06
@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.
msg189049 - (view) Author: Yogesh Chaudhari (Yogesh.Chaudhari) * Date: 2013-05-12 17:07
Please replace integer.__format__(s) with integer.__format__('')
msg189062 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2013-05-12 20:43
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: >>> class C: pass ... >>> format(C(), '1') Traceback (most recent call last): File "", line 1, in 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 "", line 1, in 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.
msg189068 - (view) Author: Yogesh Chaudhari (Yogesh.Chaudhari) * Date: 2013-05-12 22:06
>It's this case that is currently an error, but it need not be: >>>> format(object(), '1') >Traceback (most recent call last): > File "", line 1, in >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 "", line 1, in TypeError: non-empty format string passed to object.__format__ >>> format((1,2,3), '5') Traceback (most recent call last): File "", line 1, in 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.
msg189089 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-05-13 02:07
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.
msg189107 - (view) Author: Yogesh Chaudhari (Yogesh.Chaudhari) * Date: 2013-05-13 08:32
+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"
msg189586 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-05-19 13:11
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 :)
msg205017 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-12-02 15:29
Perhaps the versionchanged tag for format() is more suitable than versionadded.
msg211041 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-02-11 23:34
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
History
Date User Action Args
2022-04-11 14:57:06 admin set github: 54065
2014-02-11 23:34:43 python-dev set messages: +
2013-12-02 15:29:40 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2013-05-19 13:11:53 r.david.murray set status: open -> closednosy: + r.david.murraymessages: + resolution: fixedstage: resolved
2013-05-13 08:32:41 Yogesh.Chaudhari set messages: +
2013-05-13 02:07:09 terry.reedy set messages: +
2013-05-12 22:06:22 Yogesh.Chaudhari set messages: +
2013-05-12 20:43:15 eric.smith set messages: +
2013-05-12 17:07:39 Yogesh.Chaudhari set messages: +
2013-05-12 17:06:33 Yogesh.Chaudhari set nosy: + Yogesh.Chaudharimessages: +
2013-02-16 06:51:53 Ankur.Ankan set nosy: + Ankur.Ankan
2012-12-23 16:28:46 asvetlov set messages: +
2012-12-23 16:19:25 eric.smith set status: closed -> openresolution: fixed -> (no value)messages: + stage: resolved -> (no value)
2012-12-23 13:19:26 asvetlov set messages: +
2012-12-23 13:12:31 python-dev set messages: +
2012-12-23 12:42:02 asvetlov set status: open -> closedresolution: fixedmessages: + stage: resolved
2012-12-23 12:27:27 python-dev set messages: +
2012-12-23 10:28:31 krinart set nosy: + krinart, asvetlovmessages: +
2012-10-26 10:21:43 berker.peksag set nosy: - berker.peksag
2012-02-14 10:51:35 Arfrever set nosy: + Arfrever
2011-12-12 19:55:25 flox set files: + issue9856_python-3.4.diffnosy: + floxmessages: + keywords: + patch
2011-12-12 13:57:18 flox unlink issue13248 dependencies
2011-12-12 12:47:27 flox link issue13248 dependencies
2011-12-12 11:58:53 berker.peksag set nosy: + berker.peksag
2011-03-13 17:47:24 eric.smith set priority: release blocker -> deferred blockernosy:terry.reedy, eric.smith, python-dev
2011-03-12 15:14:31 eric.smith set priority: normal -> release blockerversions: + Python 3.4, - Python 3.3nosy:terry.reedy, eric.smith, python-devtitle: Change object.__format__(s) where s is non-empty to a DeprecationWarning -> Change object.__format__(s) where s is non-empty to a TypeErrormessages: +
2011-03-12 15:09:06 python-dev set nosy: + python-devmessages: +
2010-09-18 03:23:01 terry.reedy set nosy: + terry.reedymessages: +
2010-09-14 17:26:57 eric.smith create