Ammar Askar <[email protected]> added the comment:
Thanks for the insight Terry.
I think the functions that accept ints as bools are kind of a red herring:
Booleans were only formally introduced in Python 2.3 [1], thus any functions
that existed before that accepted ints and continued to accept ints for
backwards compatibility [2]. When transition to argument clinic, these
functions use "bool(accept={int})" which restricts the inputs to either bools
or ints [3].
print, int.to_bytes and int.from_bytes all use argument clinic's bool converter
which accepts any truth-y objects. This is similar to PyArg_ParseTuple's 'p'
parameter which also accepts any truthy objects as well as say the print
function which manually does a PyObject_IsTrue [4].
[1] https://www.python.org/download/releases/2.3/highlights/
[2] list.sort (sorted) existed since the start of Python:
https://github.com/python/cpython/blob/85a5fbbdfea617f6cc8fae82c9e8c2b5c424436d/Objects/listobject.c#L423
splitlines exists in Python 2.0:
https://github.com/python/cpython/commit/4c08d554b9009899780a5e003d6bbeb5413906ee
[3]
https://docs.python.org/3/howto/clinic.html#using-real-argument-clinic-converters-instead-of-legacy-converters
[4]
https://github.com/python/cpython/blob/7fcc2088a50a4ecb80e5644cd195bee209c9f979/Python/bltinmodule.c#L1888
----------
nosy: +ammar2
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue37980>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com