On Wed, Oct 27, 2021 at 4:07 PM Christopher Barker <python...@gmail.com> wrote:
>
> It's not actually documented that None indicates "use the default".
>
> Which, it turns out is because it doesn't :-)
>
> In [24]: bisect.bisect([1,3,4,6,8,9], 5, hi=None)
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> <ipython-input-24-65fd10e3a3b5> in <module>
> ----> 1 bisect.bisect([1,3,4,6,8,9], 5, hi=None)
>
> TypeError: 'NoneType' object cannot be interpreted as an integer
>
> I guess that's because in C there is a way to define optional other than 
> using a sentinel? or it's using an undocumented sentinal?
>
> Note: that's python 3.8 -- I can't imagine anything;s changed, but ...
>

Actually it has. The C-accelerated version of the function changed its
signature between 3.8 and 3.11 - probably when Argument Clinic got
deployed.

bisect_right(...)
    bisect_right(a, x[, lo[, hi]]) -> index

So, yes, the 3.8 version of it does indeed use "optional" without a
default. And code that passes None directly is buggy.

ChrisA
_______________________________________________
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/5IGRMA5KTQ44AXBIO66PXSZ4SKLFTAJ7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to