[Python-3000-checkins] r58914 - in python/branches/py3k: Lib/io.py Lib/test/test_io.py Modules/_fileio.c
Guido van Rossum
guido at python.org
Fri Nov 9 02:08:37 CET 2007
Sure; or perhaps better
try:
pos = pos.__index__()
except AttributeError as err:
raise TypeError("an integer is required") from err
On Nov 8, 2007 5:05 PM, Christian Heimes <lists at cheimes.de> wrote:
> Guido van Rossum wrote:
> > Actually, requiring isinstance(pos, int) is too rigid. You should use
> > __index__() instead, which allows other int-like numbers but not float
> > numbers.
>
> I wasn't familiar with the __index__() method.
>
> Is this fine with you?
>
> def seek(self, pos, whence=0):
> if not hasattr(pos, "__index__"):
> raise TypeError("an integer is required")
> pos = pos.__index__()
> if whence == 0:
> ...
>
> I want it to raise a TypeError to keep it consistent with _fileio's seek.
>
> Christian
>
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000-checkins
mailing list