raising a io exception when fileno is requested on a tarfile FileInFile

Hi, When you call extractfile() on a TarFile, the result is a buffered version of a _FileInFile pseudo-file. When fileno() is called on this resulting file, fileno() it not exist (understandably) and an AttributeError is raised. I would like to suggest raising an io.UnsupportedOperation instead, so that file would act more like other file-like objects.

makapuf2@gmail.com writes:
When you call extractfile() on a TarFile, the result is a buffered version of a _FileInFile pseudo-file. When fileno() is called on this resulting file, fileno() it not exist (understandably) and an AttributeError is raised. I would like to suggest raising an io.UnsupportedOperation instead, so that file would act more like other file-like objects.
I have no opinion on the suggestion itself, but it's well-formulated and plausible. That said, it's a clear backward incompatibility because code currently expecting AttributeError exceptions won't catch this (unless io.UnsupportedOperation is derived from AttributeError), so it will have to wait until the next feature release for sure, and might need a deprecation cycle. I suggest that you file an issue on the GitHub tracker so it won't get lost, and post it to this thread. Steve
participants (2)
-
makapuf2@gmail.com
-
Stephen J. Turnbull