GeezerVison is showing github.com — Float documentation doesn't allow int-like strings as valid arguments for float · Issue #100428 · python/cpython
Float documentation doesn't allow int-like strings as valid arguments for float #100428DescriptionThe documentation for float doesn't explicitly allow int-like strings, although it does give one as an example. E.g. although float('10') works and returns a float, the documentation implies that it shouldn't.
See discussion on Discuss.
Linked PRs
Activitymdickinson commented on Dec 22, 2022 Maybe remove the indirection (the reference to floating-point literals) from the current documentation and give a direct description of what's permitted instead? That way the information is all in one place. The current documentation feels as though it was a shortcut taken for ease of documentation writing rather than ease of documentation reading.
On the other hand, it's definitely useful for users to know that any string that's acceptable as a floating-point literal is also acceptable as a string argument to float. mdickinson commented on Dec 22, 2022 Another way in which the indirection is inaccurate is that float accepts arbitrary Unicode digits, while literals may only use ASCII digits:
>>> s = '666.0'
>>> float(s)
666.0
>>> eval(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
666.0
^
SyntaxError: invalid character '6' (U+FF16)hauntsaninja commented on Dec 22, 2022 There are inaccuracies in the int documentation too, for instance, the handling of leading zeros isn't really described. Also the following isn't correct:
Base 0 means to interpret exactly as a code literal
>>> s = "२३४५६७८९"
>>> int(s, 0)
23456789
>>> eval(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
२३४५६७८९
^
SyntaxError: invalid character '२' (U+0968)
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|