improve error message when missing 'self' in method definition
Hi all, I read this paper today about common mistakes that Python beginners make: https://www.researchgate.net/publication/307088989_Some_Trouble_with_Transpa... 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
I'm +1 On Tue, Sep 27, 2016 at 7:19 PM, Carl Friedrich Bolz <cfbolz@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_Transpa...
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@python.org https://mail.python.org/mailman/listinfo/pypy-dev
Have you considered bringing this up on python-ideas, too? On Tue, Sep 27, 2016 at 12:19 PM, Carl Friedrich Bolz <cfbolz@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@python.org https://mail.python.org/mailman/listinfo/pypy-dev
-- Ryan [ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong. http://kirbyfan64.github.io/
On Tue, Sep 27, 2016 at 8:33 PM, Ryan Gonzalez <rymg19@gmail.com> wrote:
Have you considered bringing this up on python-ideas, too?
python-idea is generally quite a hostile place. That said, if you think it's worth your effort to submit it there, feel free to do so, just the core pypy devs feel their time is better spent elsewhere than arguing on python-ideas
On Tue, Sep 27, 2016 at 12:19 PM, Carl Friedrich Bolz <cfbolz@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_Transpa...
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@python.org https://mail.python.org/mailman/listinfo/pypy-dev
-- Ryan [ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong. http://kirbyfan64.github.io/
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
I've already proposed something like this a looong time ago and guido even said it is a good idea. I never got around to implementing it. How difficult would be to port this to CPython? The patch seems very concise On Wed, Sep 28, 2016 at 8:17 AM, Maciej Fijalkowski <fijall@gmail.com> wrote:
On Tue, Sep 27, 2016 at 8:33 PM, Ryan Gonzalez <rymg19@gmail.com> wrote:
Have you considered bringing this up on python-ideas, too?
python-idea is generally quite a hostile place. That said, if you think it's worth your effort to submit it there, feel free to do so, just the core pypy devs feel their time is better spent elsewhere than arguing on python-ideas
On Tue, Sep 27, 2016 at 12:19 PM, Carl Friedrich Bolz <cfbolz@gmx.de>
wrote:
Hi all,
I read this paper today about common mistakes that Python beginners make:
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@python.org https://mail.python.org/mailman/listinfo/pypy-dev
-- Ryan [ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong. http://kirbyfan64.github.io/
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
-- Leonardo Santagada
On 03/10/16 10:53, Leonardo Santagada wrote:
I've already proposed something like this a looong time ago and guido even said it is a good idea. I never got around to implementing it. How difficult would be to port this to CPython? The patch seems very concise
Ah, cool. Do you have a link to the mailing list discussion? Anyway, the implementation is going to be slightly more complex, to reduce the false positive rate. So I have no idea how easy it would be to port to CPython. Cheers, Carl Friedrich
On Mon, Oct 3, 2016 at 7:01 PM, Carl Friedrich Bolz <cfbolz@gmx.de> wrote:
Ah, cool. Do you have a link to the mailing list discussion?
Oh I really couldn't find it, maybe my memory is failing me (i did found a discussion from 2007 about something related to that (internationalization of messages, but there is no input from Guido and the discussion didn't go anywhere) I can take it to python-ideas and see it through. -- Leonardo Santagada
participants (4)
-
Carl Friedrich Bolz
-
Leonardo Santagada
-
Maciej Fijalkowski
-
Ryan Gonzalez