Re: [Python-Dev] Error message for wrong number of arguments
On 4 August 2018 at 05:34, Jeroen Demeyer 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 :) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Error message for wrong number of arguments
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. Jeroen. ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Error message for wrong number of arguments
Actually, scratch that, I posted too soon. There is also a block /*[clinic input] class list "PyListObject *" "_Type" [clinic start generated code]*/ So it could work. ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Error message for wrong number of arguments
Actually, I just realized that it's not really possible to fix the error messages for built-in methods. The problem is that Argument Clinic does not know whether a function or method is being handled. For example, there is no indication at all that this is a method (note that the name "list.insert" might refer to a function "insert" inside a module called "list" or a method "insert" or a class "list"): /*[clinic input] list.insert index: Py_ssize_t object: object / Insert object before index. [clinic start generated code]*/ ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Error message for wrong number of arguments
On 08/01/2018 02:40 PM, Armin Rigo wrote: I think that argument clinic knows if the built-in function is supposed to be a method or a function. Yes, Argument Clinic knows. Clinic's "Function" instances have a "cls" member, and if that's set to a Clinic "Class" instance--and it's not one of the special methods like new or init--then it's a normal method. It doesn't look too hard to add a new flag METH_IS_METHOD or something, which would be taken in consideration in the common cases, and which can be added manually OR used automatically by argument clinic. Yes, Clinic could easily automatically generate such a flag. //arry/ ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Error message for wrong number of arguments
On Wed, Aug 1, 2018 at 2:40 PM, Armin Rigo wrote: > On 30 July 2018 at 22:19, Chris Barker via Python-Dev > wrote: > > Oh well. This is a serious usability issue -- but what can you do? > > I think that argument clinic knows if the built-in function is > supposed to be a method or a function. It doesn't look too hard to > add a new flag METH_IS_METHOD or something, which would be taken in > consideration in the common cases, and which can be added manually OR > used automatically by argument clinic. This would not be a 100% > solution out of the box, but if the new wording is right, it shouldn't > be a problem. > But can you do the same thing with pure-python methods? After all, this thread started with trying ot unify what error folks get regardless of how the method was written. -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Error message for wrong number of arguments
Hi, On 30 July 2018 at 22:19, Chris Barker via Python-Dev wrote: > Oh well. This is a serious usability issue -- but what can you do? I think that argument clinic knows if the built-in function is supposed to be a method or a function. It doesn't look too hard to add a new flag METH_IS_METHOD or something, which would be taken in consideration in the common cases, and which can be added manually OR used automatically by argument clinic. This would not be a 100% solution out of the box, but if the new wording is right, it shouldn't be a problem. A bientôt, Armin. ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Error message for wrong number of arguments
On Mon, Jul 30, 2018 at 11:39 AM, Jeroen Demeyer wrote: > On 2018-07-30 20:22, Chris Barker wrote: > >> is it possible for the interpreter to know when this error is >> generated that this is a bound method expecting a "self", rather than an >> arbitrary function with n parameters? >> > > That would be quite hard. The error message is generated by the underlying > function. At that point, the information of how it was called (as bound > method or not) is already gone. Thanks, I figured as much. Oh well. This is a serious usability issue -- but what can you do? -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Error message for wrong number of arguments
On 2018-07-30 20:22, Chris Barker wrote: is it possible for the interpreter to know when this error is generated that this is a bound method expecting a "self", rather than an arbitrary function with n parameters? That would be quite hard. The error message is generated by the underlying function. At that point, the information of how it was called (as bound method or not) is already gone. Jeroen. ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Error message for wrong number of arguments
On Mon, Jul 30, 2018 at 5:12 AM, Jeroen Demeyer wrote: > I think it has been argued before that it's a feature that self is > counted. I suppose it is, as it's technically correct, but it's also a HUGE source of confusion, particularly for newbies. IF this is being touched anyway, is it possible for the interpreter to know when this error is generated that this is a bound method expecting a "self", rather than an arbitrary function with n parameters? In which case, it would be really nice if the error message replaced that somehow, maybe something like: >>> g(1,2) Traceback (most recent call last): File "", line 1, in TypeError: append() takes 1 positional argument in addition to the automatically added instance object -- but 2 were given in addition to the object instance. Man -- hard to come up with good wording for that -- but SOMETHING that lets users know what they actually did wrong would be good :-) If it's not do-able, then still +1 on making builtins consistent. -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Error message for wrong number of arguments
On 30 July 2018 at 22:12, Jeroen Demeyer wrote: > I think it has been argued before that it's a feature that self is counted. > So I consider the error message for list().append a bug. This is one of the > many oddities I noticed while working on improving built-in functions. > > Would you agree to change the error message for built-in methods to be > closer to Python methods? 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. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com