diff options
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r-- | Lib/_pyio.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 8960ce9..c58548e 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -828,7 +828,7 @@ class BytesIO(BufferedIOBase): if self.closed: raise ValueError("seek on closed file") try: - pos = pos.__index__() + pos.__index__ except AttributeError as err: raise TypeError("an integer is required") from err if whence == 0: @@ -853,8 +853,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 as err: + raise TypeError("an integer is required") from err + if pos < 0: + raise ValueError("negative truncate position %r" % (pos,)) del self._buffer[pos:] return pos @@ -1803,6 +1808,10 @@ class TextIOWrapper(TextIOBase): if n is None: n = -1 decoder = self._decoder or self._get_decoder() + try: + n.__index__ + except AttributeError as err: + raise TypeError("an integer is required") from err if n < 0: # Read everything. result = (self._get_decoded_chars() + |