Issue #6241: Better type checking for the arguments of io.StringIO.

This commit is contained in:
Alexandre Vassalotti 2009-07-22 03:07:33 +00:00
parent e671fd206b
commit d2bb18b281
3 changed files with 38 additions and 5 deletions

View file

@ -1924,8 +1924,10 @@ class StringIO(TextIOWrapper):
# C version, even under Windows.
if newline is None:
self._writetranslate = False
if initial_value:
if initial_value is not None:
if not isinstance(initial_value, str):
raise TypeError("initial_value must be str or None, not {0}"
.format(type(initial_value).__name__))
initial_value = str(initial_value)
self.write(initial_value)
self.seek(0)