[issue40825] Add a "strict" parameter to csv.writer and csv.DictWriter

2020-06-02 Thread Eric V. Smith
Eric V. Smith added the comment: I wouldn't have a problem with isinstance(obj, str) for a string check in strict mode. If you want to write something like a Path, convert it to a string yourself. That's exactly the behavior I'd like enforced by strict: only accept numbers and actual

[issue40825] Add a "strict" parameter to csv.writer and csv.DictWriter

2020-05-31 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Yes, converting Decimal to float can lose precision, so we cannot require this. PyNumber_Check() is already used for QUOTE_NONNUMERIC, so it would be logical to use it in determining that the object is a number in the cvs module. But now the problem is

[issue40825] Add a "strict" parameter to csv.writer and csv.DictWriter

2020-05-31 Thread Eric V. Smith
Eric V. Smith added the comment: That seems like a good plan. -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue40825] Add a "strict" parameter to csv.writer and csv.DictWriter

2020-05-31 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: We can check only nb_index and nb_float. It will include Fraction, Decimal and NumPy numbers and exclude UUID and IPv4Address. -- ___ Python tracker

[issue40825] Add a "strict" parameter to csv.writer and csv.DictWriter

2020-05-31 Thread Eric V. Smith
Eric V. Smith added the comment: Losing Decimal would be a problem. I use those a lot in CSV files, and I assume others do, too. -- ___ Python tracker ___

[issue40825] Add a "strict" parameter to csv.writer and csv.DictWriter

2020-05-31 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: There is PyNumber_Check(). It is not direct analog of isinstance(obj, numbers.Number), it checks that the object can be explicitly converted to the real number (int or float). UUID and IPv4Address pass this check. As a narrow check we can use

[issue40825] Add a "strict" parameter to csv.writer and csv.DictWriter

2020-05-30 Thread Eric V. Smith
Eric V. Smith added the comment: I guess an isinstance check against numbers.Number would be the best way to check if an argument is a number. I'm not sure how convenient that is from C code. -- ___ Python tracker

[issue40825] Add a "strict" parameter to csv.writer and csv.DictWriter

2020-05-30 Thread Dong-hee Na
Dong-hee Na added the comment: I am +1 on with strict mode. But I want to hear other core developers opinions. -- nosy: +corona10, serhiy.storchaka ___ Python tracker ___

[issue40825] Add a "strict" parameter to csv.writer and csv.DictWriter

2020-05-30 Thread Eric V. Smith
Eric V. Smith added the comment: For backward compatibility, strict would have to default to False. -- ___ Python tracker ___ ___

[issue40825] Add a "strict" parameter to csv.writer and csv.DictWriter

2020-05-30 Thread Eric V. Smith
New submission from Eric V. Smith : Currently, the csv library calls str() on each value it writes. This can lead to surprising behavior, see issue40762 for example. On the other hand, for writing the documentation says that the values must be strings or numbers. The proposed "strict"