[pypy-dev] improve error message when missing 'self' in method definition

Maciej Fijalkowski fijall at gmail.com
Tue Sep 27 13:53:49 EDT 2016


I'm +1

On Tue, Sep 27, 2016 at 7:19 PM, Carl Friedrich Bolz <cfbolz at gmx.de> wrote:
> Hi all,
>
> I read this paper today about common mistakes that Python beginners
> make:
>
> https://www.researchgate.net/publication/307088989_Some_Trouble_with_Transparency_An_Analysis_of_Student_Errors_with_Object-oriented_Python
>
> The most common one by far is forgetting the "self" parameter in the
> method definition (which also still happens to me regularly). The error
> message is not particularly enlightening, if you don't quite understand
> the explicit self in Python.
>
>
> So I wonder whether we should print a better error message, something
> like this:
>
> $ cat m.py
> class A(object):
>     def f(x):
>         return self.x
> A().f(1)
>
> $ pypy m.py
> Traceback (application-level):
>   File "m.py", line 4 in <module>
>     A().f(1)
> TypeError: f() takes exactly 1 argument (2 given). Did you forget 'self'
> in the function definition?
>
>
> It's a bit the question how clever we would like this to be to reduce
> false positives, see the attached patch for a very simple approach.
>
> Anyone have opinions?
>
> Cheers,
>
> Carl Friedrich
>
> _______________________________________________
> pypy-dev mailing list
> pypy-dev at python.org
> https://mail.python.org/mailman/listinfo/pypy-dev
>


More information about the pypy-dev mailing list