]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Insist that the argument to TextIOWrapper.write() is a basestring
authorGuido van Rossum <guido@python.org>
Wed, 29 Aug 2007 18:10:08 +0000 (18:10 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 29 Aug 2007 18:10:08 +0000 (18:10 +0000)
instance.  This was effectively already the case, but the error
reporting was lousy.

Lib/io.py

index 7aa79ce1d80418079ede33c9d21a4101b35015a8..375ae6e2c89de3c6a7241d8bfe4ea34422be1c78 100644 (file)
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -1093,6 +1093,9 @@ class TextIOWrapper(TextIOBase):
     def write(self, s: str):
         if self.closed:
             raise ValueError("write to closed file")
+        if not isinstance(s, basestring):
+            raise TypeError("can't write %s to text stream" %
+                            s.__class__.__name__)
         haslf = "\n" in s
         if haslf and self._writetranslate and self._writenl != "\n":
             s = s.replace("\n", self._writenl)