[Python-Dev] Error message for wrong number of arguments
ncoghlan at gmail.com
Sat Aug 4 04:20:14 EDT 2018
On 4 August 2018 at 05:34, Jeroen Demeyer <J.Demeyer at ugent.be> wrote:
> On 2018-07-30 17:28, Nick Coghlan wrote:
>> I would, and I think it would make sense for the PEP to cite improving
>> consistency (and reducing code duplication?) in that regard as an
>> advantage of the PEP.
> I'm not sure to which PEP you are referring (PEP 580 or a new PEP?). After
> thinking a bit about the issue of error messages, I realized that PEP 580
> would make this easier to fix (to be clear: there are ways to fix it without
> PEP 580, I'm just saying that PEP 580 makes it easier). There are two
> related reasons for this:
> * The existing code which calls the actual underlying C function doesn't
> have access to the Python-level function object. So it can't know whether
> it's a function (where self doesn't count) or a method (where self counts).
> * Armin Rigo suggested to use a new flag to indicate this difference: that
> would certainly work for Argument Clinic (just have Argument Clinic add that
> flag). For methods defined without Argument Clinic, we cannot require such a
> new flag though. We could still add the flag at runtime, but it's far from
> clear if we can freely change the flags inside a PyMethodDef at runtime (at
> least, no existing code that I know does that).
> PEP 580 solves the first issue by having the function object available and
> it solves the second issue by not relying on PyMethodDef at all for calling
> functions/methods. The second issue especially can be generalized as: PEP
> 580 makes the implementation of functions/methods much less rigid, making it
> easier to change the implementation.
> So maybe this can be seen as yet another advantage of PEP 580.
Yes, this is the kind of framing of the issue that I had in mind :)
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev