22.12.20 02:52, Christopher Barker пише:
> On Mon, Dec 21, 2020 at 3:37 PM Greg Ewing <greg.ew...@canterbury.ac.nz
> <mailto:greg.ew...@canterbury.ac.nz>> wrote:
>     > However, that ship has sailed. I think it would have been minimally
>     > disruptive when True and False were first introduced,
> 
>     It would have been just as disruptive back then -- that's the
>     reason bool was made a subclass of int in the first place.
> 
> 
> I know why, but I'm not so sure -- no one was using a built in True or
> False as an integer, because they didn't exist. I suppose folks were
> using the results of, e.g.  `a == b` as an integer, but how often? Where
> else is an explicit True or False returned by Python itself?

Every time you use a builtin function which has semantically boolean
parameter. They are usually converted to C using PyArg_Parse("i").

For example:

>>> sorted('abc', reverse=0)
['a', 'b', 'c']
>>> sorted('abc', reverse=42)
['c', 'b', 'a']
>>> sorted('abc', reverse=[])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'list' object cannot be interpreted as an integer

There are tons of such parameters in the stdlib (it can be changed) and
zillions of them in third-party extensions which will be broken with
non-int booleans.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/MTAOAXBLY5N6VO476GHEJRSAHEV24FEW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to