]> granicus.if.org Git - python/commitdiff
Issue #19481: print() of unicode, str or bytearray subclass instance in IDLE
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 10 Dec 2013 08:04:41 +0000 (10:04 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 10 Dec 2013 08:04:41 +0000 (10:04 +0200)
no more hangs.

Lib/idlelib/PyShell.py
Misc/NEWS

index 7a9a0bc01b98cae1b1c35662b179e0be583f3980..89f32a7ebf11c8888207121fa3c3e2c230b5fa7e 100644 (file)
@@ -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)
 
 
index 8ac5672d5852036ce2e179f465922e6c2dfe489f..30b796716ff94d4a68911038770e83525fb268c7 100644 (file)
--- 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
 -----