From: Serhiy Storchaka Date: Tue, 10 Dec 2013 08:04:41 +0000 (+0200) Subject: Issue #19481: print() of unicode, str or bytearray subclass instance in IDLE X-Git-Tag: v2.7.8~213 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7057f3fa4db3df28148c6b764e92789b07271689;p=python Issue #19481: print() of unicode, str or bytearray subclass instance in IDLE no more hangs. --- diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index 7a9a0bc01b..89f32a7ebf 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -1338,8 +1338,16 @@ class PseudoOutputFile(PseudoFile): def write(self, s): if self.closed: raise ValueError("write to closed file") - if not isinstance(s, (basestring, bytearray)): - raise TypeError('must be string, not ' + type(s).__name__) + if type(s) not in (unicode, str, bytearray): + # See issue #19481 + if isinstance(s, unicode): + s = unicode.__getslice__(s, None, None) + elif isinstance(s, str): + s = str.__str__(s) + elif isinstance(s, bytearray): + s = bytearray.__str__(s) + else: + raise TypeError('must be string, not ' + type(s).__name__) return self.shell.write(s, self.tags) diff --git a/Misc/NEWS b/Misc/NEWS index 8ac5672d58..30b796716f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -68,6 +68,12 @@ Library - Issue #19286: Directories in ``package_data`` are no longer added to the filelist, preventing failure outlined in the ticket. +IDLE +---- + +- Issue #19481: print() of unicode, str or bytearray subclass instance in IDLE + no more hangs. + Tests -----