From: Guido van Rossum Date: Wed, 29 Aug 2007 18:10:08 +0000 (+0000) Subject: Insist that the argument to TextIOWrapper.write() is a basestring X-Git-Tag: v3.0a1~135 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dcce8391d1c76ebc6f81a0d22224e29f0a9f0c49;p=thirdparty%2FPython%2Fcpython.git Insist that the argument to TextIOWrapper.write() is a basestring instance. This was effectively already the case, but the error reporting was lousy. --- diff --git a/Lib/io.py b/Lib/io.py index 7aa79ce1d804..375ae6e2c89d 100644 --- 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)