Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csv.reader accepts string instead of file object (duck typing gone bad) #46953

Closed
roysmith mannequin opened this issue Apr 27, 2008 · 3 comments
Closed

csv.reader accepts string instead of file object (duck typing gone bad) #46953

roysmith mannequin opened this issue Apr 27, 2008 · 3 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@roysmith
Copy link
Mannequin

roysmith mannequin commented Apr 27, 2008

BPO 2701
Nosy @smontanaro, @facundobatista

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2008-06-21.15:48:58.320>
created_at = <Date 2008-04-27.02:59:50.468>
labels = ['invalid', 'type-bug', 'library']
title = 'csv.reader accepts string instead of file object (duck typing gone bad)'
updated_at = <Date 2008-06-21.15:48:58.269>
user = 'https://bugs.python.org/roysmith'

bugs.python.org fields:

activity = <Date 2008-06-21.15:48:58.269>
actor = 'facundobatista'
assignee = 'none'
closed = True
closed_date = <Date 2008-06-21.15:48:58.320>
closer = 'facundobatista'
components = ['Library (Lib)']
creation = <Date 2008-04-27.02:59:50.468>
creator = 'roysmith'
dependencies = []
files = []
hgrepos = []
issue_num = 2701
keywords = []
message_count = 3.0
messages = ['65871', '65884', '68502']
nosy_count = 3.0
nosy_names = ['skip.montanaro', 'facundobatista', 'roysmith']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue2701'
versions = ['Python 2.5']

@roysmith
Copy link
Mannequin Author

roysmith mannequin commented Apr 27, 2008

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.

@roysmith roysmith mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 27, 2008
@smontanaro
Copy link
Contributor

It's not a mistake. In fact, the csv unit tests make use of being able
to iterate over strings. I don't think this feature is going away.

@facundobatista
Copy link
Member

Skip is right, this is working ok.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants