Author skip.montanaro
Recipients MiK, docs@python, r.david.murray, skip.montanaro
Date 2015-05-17.14:50:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1431874232.39.0.885978525558.issue24147@psf.upfronthosting.co.za>
In-reply-to
Content
The defaults for the Dialect class are documented:

https://docs.python.org/2/library/csv.html#dialects-and-formatting-parameters

I think the problem is mostly that csv.Dialect must be subclassed. You can't use it directly, and if you subclass it as MiK did, you have to supply all the missing parameters. The default dialect is actually csv.excel, which does provide a suitable set of values for all attributes.

There actually might be a bug lurking in the code as well. The value of csv.Dialect.doublequote is None, which will evaluate to False in a boolean context. The module docstring has this to say about that attribute:

        * doublequote - controls the handling of quotes inside fields.  When
            True, two consecutive quotes are interpreted as one during read,
            and when writing, each quote character embedded in the data is
            written as two quotes

Since the valid values of that attribute are actually only True and False, using None as a default value is an invitation to problems. It appears in this case that's what happened.

csv.Dialect.__init__ doesn't seem to check that the overriding class properly sets all the required parameters. It checks to see if the class is Dialect. If not, and if the validate() call passes, all is assumed to be well. But digging a bit under the surface, it appears the validate step drops into C where the doublequote attribute of Dialog_Type is 0.

I'm not sure the bug should be fixed in 2.7, but it's worth taking a look at the 3.5 code to see if that validation step can be improved.
History
Date User Action Args
2015-05-17 14:50:32skip.montanarosetrecipients: + skip.montanaro, r.david.murray, docs@python, MiK
2015-05-17 14:50:32skip.montanarosetmessageid: <1431874232.39.0.885978525558.issue24147@psf.upfronthosting.co.za>
2015-05-17 14:50:32skip.montanarolinkissue24147 messages
2015-05-17 14:50:32skip.montanarocreate