mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Implement the changes proposed in patch #413333. unicode(obj) now
works just like str(obj) in that it tries __str__/tp_str on the object in case it finds that the object is not a string or buffer.
This commit is contained in:
parent
c60e6f7771
commit
6871f6ac57
2 changed files with 61 additions and 43 deletions
|
@ -429,6 +429,7 @@ verify(unicode('hello','utf-8') == u'hello')
|
|||
verify(unicode('hello','utf8') == u'hello')
|
||||
verify(unicode('hello','latin-1') == u'hello')
|
||||
|
||||
# Compatibility to str():
|
||||
class String:
|
||||
x = ''
|
||||
def __str__(self):
|
||||
|
@ -444,6 +445,10 @@ o.x = u'abc'
|
|||
verify(unicode(o) == u'abc')
|
||||
verify(str(o) == 'abc')
|
||||
|
||||
for obj in (123, 123.45, 123L):
|
||||
verify(unicode(obj) == unicode(str(obj)))
|
||||
|
||||
# Error handling
|
||||
try:
|
||||
u'Andr\202 x'.encode('ascii')
|
||||
u'Andr\202 x'.encode('ascii','strict')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue