Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue1583863

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:__str__ cannot be overridden on unicode-derived classes
Type:behaviorStage:test needed
Components:Interpreter Core, UnicodeVersions:Python 2.6
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: ajaksu2, laughingboy0, vstinner
Priority:normalKeywords:patch

Created on2006-10-24 15:57 bylaughingboy0, last changed2022-04-11 14:56 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
format_unicode.patchvstinner,2009-03-30 11:45
Messages (5)
msg61028 -(view)Author: Mike K (laughingboy0)Date: 2006-10-24 15:57
class S(str):   def __str__(self): return '__str__ overridden'class U(unicode):   def __str__(self): return '__str__ overridden'   def __unicode__(self): return u'__unicode__ overridden's = S()u = U()print 's:', sprint "str(s):", str(s)print 's substitued is "%s"\n' % sprint 'u:', uprint "str(u):", str(u)print 'u substitued is "%s"' % u-----------------------------------------------------s: __str__ overriddenstr(s): __str__ overriddens substitued is "__str__ overridden"u:str(u): __str__ overriddenu substitued is ""Results are identical for 2.4.2 and 2.5c2 (runningunder windows).
msg84519 -(view)Author: Daniel Diniz (ajaksu2)*(Python triager)Date: 2009-03-30 06:42
Confirmed in trunk.
msg84534 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2009-03-30 10:51
Case "S" (type str): "%s" uses _PyObject_Str() which checks the object type with PyString_CheckExact().Case "U" (type unicode) "%s" uses PyUnicode_Check() and then calls PyUnicode_Format(). PyUnicode_Format() uses PyUnicode_Check() to check the object object. It should uses PyUnicode_CheckExact() instead.xxx_CheckExact() is different than xxx_Check(): exact is only true for the base type, whereas the the second is also true for subclass.
msg84535 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2009-03-30 11:45
Patch: Use PyUnicode_CheckExact() instead of PyUnicode_CheckExact() in PyUnicode_Format() to use obj.__unicode__ slot.
msg101501 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2010-03-22 12:56
Commited:r79278+r79280 (trunk),r79281 (py3k),r79282 (3.1),r79283 (2.6).
History
DateUserActionArgs
2022-04-11 14:56:20adminsetgithub: 44163
2010-04-27 14:45:23eric.smithlinkissue8128 superseder
2010-03-22 12:57:04vstinnersetstatus: open -> closed
resolution: fixed
2010-03-22 12:56:53vstinnersetmessages: +msg101501
2009-03-30 11:45:53vstinnersetfiles: +format_unicode.patch
keywords: +patch
messages: +msg84535
2009-03-30 10:51:54vstinnersetmessages: +msg84534
2009-03-30 06:42:29ajaksu2settype: behavior
components: + Unicode
versions: + Python 2.6, - Python 2.5
nosy: +ajaksu2,vstinner

messages: +msg84519
stage: test needed
2006-10-24 15:57:03laughingboy0create
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp