[Python-ideas] Improve error message when missing 'self' in method definition

Yury Selivanov yselivanov.ml at gmail.com
Wed Oct 5 19:43:40 EDT 2016



On 2016-10-05 7:34 PM, Steven D'Aprano wrote:
> On Wed, Oct 05, 2016 at 09:02:50PM +0200, Ivan Levkivskyi wrote:
>
>> >I agree with Yury here. There are corner cases (like what to do with
>> >classmethods etc). If behaviour for all of them are specified, it would be
>> >quite straightforward to implement this.
> I don't know... there's a lot of corner cases and I don't think we can
> improve them all.
>
> Here's the suggested exception from PyPy:
>
>      TypeError: f() takes exactly 1 argument (2 given). Did you forget
>      'self' in the function definition?
>
>
> What happens if f() takes a mix of positional and keyword arguments?
> What if it takes arbitrary positional arguments?
>
> There are also classmethods, staticmethods, and any arbitrary
> descriptor. And don't forget ordinary functions too. How will this
> affect them?

We can implement this only for bound methods.

Yury


More information about the Python-ideas mailing list