[Csv] _csv bug
Dave Cole
djc at object-craft.com.au
Wed Feb 5 11:11:21 CET 2003
>>>>> "Andrew" == Andrew McNamara <andrewm at object-craft.com.au> writes:
>> That sort of thing. (Speaking of which, we should probably all the
>> user to specify the hard (embedded) return character.) It's tough
>> enough in C to generate really good messages (because it often
>> requires pasting strings together on-the-fly to provide the
>> necessary context) that it frequently doesn't get done. For
>> example, if I pass None instead of an int for parameters with 'i'
>> format characters, all PyArg_PTAK says is "int was required".
>> However, there are nine args to the constructor, five of which are
>> ints.
Andrew> I'm not sure this is a good enough reason to move the checks
Andrew> away from the "coalface" - with a little more work, we can
Andrew> generate friendly messages from the C level, while at the same
Andrew> time keeping them tightly coupled to the implementation. I'd
Andrew> certainly agree the PyArg_PTAK validation is less than useful
Andrew> in our context - but I think it highlights a more fundemental
Andrew> problem in the way the C code is structured. I'll talk to Dave
Andrew> tonight and see if we can come up with something better.
We spoke for a short while and decided that it might make more sense
to remove the PyArg_PTAK stuff altogether and just use the __setattr__
stuff in _csv.
One of the problems in this approach is that PyArg_PTAK allows you to
set multiple attributes simultaneously while __setattr__ is one
attribute at a time. This means that it is not really feasible to
validate settings in the __setattr__ method - the user would have to
work out a sequence of __setattr__ steps to go from one dialect to the
next without ever having illegal parameter settings.
There are two obvious way around this that I can see.
1. Mark the parser dirty whenever __setattr__ is called then check
the dirty flag on the next method call which uses the parser. If
parser is dirty, check that the parameter set is valid.
2. Only check the legality of the parameter set when the user calls
the check_attrs() (or whatever) method.
- Dave
--
http://www.object-craft.com.au
More information about the Csv
mailing list