[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-24 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-24 Thread Roundup Robot

Roundup Robot added the comment:

New changeset cd9e4f73b5ce by Serhiy Storchaka in branch '2.7':
Issue #23583: Fixed writing unicode to standard output stream in IDLE.
https://hg.python.org/cpython/rev/cd9e4f73b5ce

New changeset 0c72cdf3ff22 by Serhiy Storchaka in branch '2.7':
Issue #23583: Fixed writing unicode to standard output stream in IDLE.
https://hg.python.org/cpython/rev/0c72cdf3ff22

New changeset 2c680d7d8ca6 by Serhiy Storchaka in branch '3.4':
Issue #23583: Added tests for standard IO streams in IDLE.
https://hg.python.org/cpython/rev/2c680d7d8ca6

New changeset f860915e5705 by Serhiy Storchaka in branch 'default':
Issue #23583: Added tests for standard IO streams in IDLE.
https://hg.python.org/cpython/rev/f860915e5705

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-04 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


Added file: http://bugs.python.org/file38338/idle_test_io-3.5.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-04 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

> does not work because there is no unicode.__unicode__.

Yes, this is why unicode.__getslice__ or unicode.__getitem__ should be used.

Here is a patch for 2.7 that fixes this issue and adds tests for 
PseudoOutputFile and PseudoInputFile. Tests should be ported also to 3.x.

--
assignee:  -> serhiy.storchaka
keywords: +patch
stage: needs patch -> patch review
Added file: http://bugs.python.org/file38337/idle_test_io-2.7.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-04 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I don't see what you have in mind.  Translating my example

class S(str):
def __str__(self):
return 'S: ' + str.__str__(self)

to

class U(unicode):
def __unicode__(self):
return u'U: ' + unicode.__unicode__(self)

does not work because there is no unicode.__unicode__.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-04 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

See example in msg205740. The same works with overridden __unicode__.

I'm writing tests now.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-04 Thread Terry J. Reedy

Terry J. Reedy added the comment:

What about just 's = unicode(s)'?  The doc says

"object.__unicode__(self)

Called to implement unicode() built-in; should return a Unicode object. 
When this method is not defined, string conversion is attempted, and the result 
of string conversion is converted to Unicode using the system default encoding."

but the latter part seems not to be true for unicode subclasses.

>>> class F(unicode):
def __str__(self): raise TypeError()

>>> f = F()
>>> u = unicode(f)
>>> type(u)


--
stage:  -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-04 Thread Martijn Pieters

Martijn Pieters added the comment:

I like the unicode.__getitem__(s, slice(None)) approach, it has the advantage 
of not having to rely on len(s).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-04 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Just len() doesn't work when the subclass overrides __len__.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-04 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I can propose two ways to fix this:

s = unicode.__getslice__(s, 0, unicode.__len__(s))

and

s = unicode.__getitem__(s, slice(None))

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-04 Thread Martijn Pieters

Martijn Pieters added the comment:

Proposed fix, replace line 1352-1353 in PseudoOutputFile.write():

if isinstance(s, unicode):
s = unicode.__getslice__(s, None, None)

with

if isinstance(s, unicode):
s = unicode.__getslice__(s, 0, len(s))

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-04 Thread Ezio Melotti

Changes by Ezio Melotti :


--
components: +Unicode
nosy: +ezio.melotti, haypo, ned.deily, serhiy.storchaka, terry.reedy
type:  -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-04 Thread Martijn Pieters

Changes by Martijn Pieters :


--
components: +IDLE

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23583] IDLE: printing unicode subclasses broken (again)

2015-03-04 Thread Martijn Pieters

New submission from Martijn Pieters:

This is a regression or recurrence of issue #19481. 

To reproduce, create a subclass of unicode and try and print an instance of 
that class:

class Foo(unicode): pass

print Foo()

results in a traceback:

Traceback (most recent call last):
  File "", line 1, in 
print Foo()
  File 
"/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/idlelib/PyShell.py",
 line 1353, in write
s = unicode.__getslice__(s, None, None)
TypeError: an integer is required

because unicode.__getslice__ does not accept None for the start and end indices.

--
messages: 237181
nosy: mjpieters
priority: normal
severity: normal
status: open
title: IDLE: printing unicode subclasses broken (again)
versions: Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com