So, according to documentation float(‘10’) is not allowed or rather not defined. Interpreters I’ve used so far have no problem with that and return a valid/expected value (10.0). Is that legal/safe/portable, though? or float(int(‘10’)) should be used instead for a maximum safety?
if it is not allowed to have integer strings as input then one of the examples in the documentation would be wrong where it shows float(' -12345\n') gives -12345.0, so I believe the intention was definitely to allow it, it is just a bug in the documentation
also, the two major implementations, cpython and pypy both work as expected, so pretty sure a lot of people already rely on it and it won’t be changed anytime soon even if it was not intended
Good spot! It’s got to be intentional that float('10') works; we should fix the grammar in the documentation. Want to open an issue on the CPython repo?
Terry’s suggestion is about right, but should probably be decinteger, not integer. Although actually, I think that doesn’t quite match the way float handles leading zeros. (We could also describe it less formally, like is done for int )