dfremont · GitHub

Bug report

Bug description:

Prior to 3.13, the following code correctly raised a TypeError (I've tested 3.8-3.12, but see the last paragraph below):

def fun(x, /, **kwargs):
    pass
import inspect
sig = inspect.signature(fun)
sig.bind(x=1)

In 3.13, the binding succeeds even though the positional-only parameter was passed as a keyword argument (of course, fun(x=1) fails with a TypeError).

As far as I can tell this bug hasn't been previously reported, although issue #107831 reports inspect.getcallargs as having the same problem (prior to 3.13, unlike this bug).

I'm guessing the bug was introduced by #103404. If I try a version of 3.12 containing that patch (rather than the older versions I had installed previously), e.g. 3.12.9, it also exhibits the bug. It's possible that fixing the case where the positional-only parameter has a default value accidentally broke this case. Mentioning @jacobtylerwalls as the author of that PR in case they would like to take a look. Thanks!

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Linked PRs

Read the original on github.com ↗