[Chicago] What to do about File Like Object methods I don't need...

Ian Bicking ianb at colorstudy.com
Sun Dec 21 19:56:53 CET 2008


Steven Githens wrote:
> My question is, when I see methods in the docs like these two:
> 
> fileno(      )
>    Return the integer ``file descriptor'' that is used by the underlying 
> implementation to request I/O operations from the operating system. This 
> can be useful for other, lower level interfaces that use file 
> descriptors, such as the fcntl module or os.read() and friends. Note: 
> File-like objects which do not have a real file descriptor should not 
> provide this method!
> 
> isatty(     )
>    Return True if the file is connected to a tty(-like) device, else 
> False. Note: If a file-like object is not associated with a real file, 
> this method should not be implemented.
> 
> 
> 
> Should I...
> 
> - really just flat out not implement them
> - or should I stub them in and throw a standard Python not implemented 
> sort of exception
> - or stub them in and just 'pass'
> - or something else?

Just don't implement them.  Almost all code when it uses these methods 
either would be flat-out unusable with your interface (for instance, 
it's doing fancy locking and other file manipulations using the fileno), 
or it expects that these methods might not defined.  Most code just 
doesn't use these methods.

-- 
Ian Bicking : ianb at colorstudy.com : http://blog.ianbicking.org


More information about the Chicago mailing list