[docs] [issue13918] locale.atof documentation is missing func argument
Terry J. Reedy
report at bugs.python.org
Fri Mar 15 21:21:07 CET 2013
Terry J. Reedy added the comment:
I find the idea of intentionally not documenting a public parameter and the full signature of a function somewhat strange, especially when it is already automatically partially-documented.
>>> import locale
Help on function atof in module locale:
atof(string, func=<class 'float'>)
Parses a string as a float according to the locale settings.
# 2.7, 3.2, 3.3
Not documenting the full signature of a function seems to me contrary to proper policy. That aside, the func parameter is, to me, a useful feature, not just an implementation detail
The way to have factored out the common normalization without a func parameter is obvious: define a private normalization function.
"remove thousands separators, make decimal dot"
ts = localeconv()['thousands_sep']
string = string.replace(ts, '')
#next, replace the decimal point with a dot
dd = localeconv()['decimal_point']
string = string.replace(dd, '.')
"Parses a string as a float according to the locale settings."
def atoi(string): # changed from str
"Converts a string to an integer according to the locale settings."
But Martin von Loewis, the original author did not do this. I would not assume that he "thought that copying 3 lines from atof into atoi was a bad idea." without asking him. Whatever his conscious intention, the func parameter *does* have the advantage of allowing alternate float string to number converters. We now have another one in the stdlib besides decimal.Decimal: fractions.Fractions.
>>> locale.atof('99,999.99', F)
There are also 3rd party float implementations, such as indefinite precision binary floats. Does anyone still object to properly documenting this useful feature? I am willing to do the commits.
As to the patch and atof docstring, I thinks 'converts' (used in atoi docstring) is better than 'parses'. So I would change both.
versions: +Python 2.7, Python 3.2, Python 3.3, Python 3.4
Python tracker <report at bugs.python.org>
More information about the docs