summaryrefslogtreecommitdiffstats
path: root/Lib/io.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/io.py')
-rw-r--r--Lib/io.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/io.py b/Lib/io.py
index 9013c58..40623d6 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -849,8 +849,8 @@ class _BytesIO(BufferedIOBase):
if self.closed:
raise ValueError("seek on closed file")
try:
- pos = pos.__index__()
- except AttributeError as err:
+ pos.__index__
+ except AttributeError:
raise TypeError("an integer is required") # from err
if whence == 0:
if pos < 0:
@@ -874,8 +874,13 @@ class _BytesIO(BufferedIOBase):
raise ValueError("truncate on closed file")
if pos is None:
pos = self._pos
- elif pos < 0:
- raise ValueError("negative truncate position %r" % (pos,))
+ else:
+ try:
+ pos.__index__
+ except AttributeError:
+ raise TypeError("an integer is required")
+ if pos < 0:
+ raise ValueError("negative truncate position %r" % (pos,))
del self._buffer[pos:]
return pos
@@ -1752,6 +1757,10 @@ class TextIOWrapper(TextIOBase):
if n is None:
n = -1
decoder = self._decoder or self._get_decoder()
+ try:
+ n.__index__
+ except AttributeError:
+ raise TypeError("an integer is required")
if n < 0:
# Read everything.
result = (self._get_decoded_chars() +