[New-bugs-announce] [issue2701] csv.reader accepts string instead of file object (duck typing gone bad)

Roy Smith report at bugs.python.org
Sun Apr 27 04:59:51 CEST 2008


New submission from Roy Smith <roy at panix.com>:

If you pass csv.reader() a filename as its first argument:

  csv.reader('filename')

instead of a file object like you're supposed to, you don't get an error.  
You instead get a reader object which returns the characters which make up 
the filename.

Technically, this is not a bug, since the documentation says, "csvfile can 
be any object which supports the iterator protocol and returns a string 
each time its next method is called", and a string meets that definition.  
Still, this is unexpected behavior, and is almost certainly not what the 
user intended.  It would be useful if a way could be devised to catch this 
kind of mistake.

----------
components: Library (Lib)
messages: 65871
nosy: roysmith
severity: normal
status: open
title: csv.reader accepts string instead of file object (duck typing gone bad)
type: behavior
versions: Python 2.5

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2701>
__________________________________


More information about the New-bugs-announce mailing list