[Python-Dev] [Python-checkins] cpython (3.3): Issue #16045: add more unit tests for built-in int()
tjreedy at udel.edu
Sun Dec 23 21:03:36 CET 2012
> + # For example, PyPy 1.9.0 raised TypeError for these cases because it
> + # expects x to be a string if base is given.
> + @support.cpython_only
> + def test_base_arg_with_no_x_arg(self):
> + self.assertEquals(int(base=6), 0)
> + # Even invalid bases don't raise an exception.
> + self.assertEquals(int(base=1), 0)
> + self.assertEquals(int(base=1000), 0)
> + self.assertEquals(int(base='foo'), 0)
I think the above behavior is buggy and should be changed rather than
frozen into CPython with a test. According to the docs, PyPy does it right.
The current online doc gives the signature as
int(x, base=10) <<where x is s string>>
The 3.3.0 docstring says
"When converting a string, use the optional base. It is an error to
supply a base when converting a non-string."
Certainly, accepting any object as a base, violating "The allowed values
are 0 and 2-36." just because giving a base is itself invalid is crazy.
Terry Jan Reedy
More information about the Python-Dev