On Tue, 7 May 2019, 19:25 Chris Angelico, <ros...@gmail.com> wrote:

> On Wed, May 8, 2019 at 4:17 AM Oscar Benjamin
> <oscar.j.benja...@gmail.com> wrote:
> > Admittedly the non-ASCII unicode digit example is not one that has
> > actually caused me a problem but what I have had a problem with is
> > floats. Given that a user of my code can pass in a float in place of a
> > string the fact that int(1.5) gives 1 can lead to bugs or confusion.
> > ...
> > There is no function to parse a decimal integer string without also
> > accepting floats though.
>
> Explicitly parse in decimal, then.
>
> >>> int(1.5, 10)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: int() can't convert non-string with explicit base
>

Good point!

Maybe that could be the solution for bytes as well: overload the
constructor even more and allow the second argument to be an integer base:

    >>> bytes(123, 10)
    b'123'

--
Oscar

>
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to