classification
Title: Traceback needs more details
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Andrew Wall, ammar2, sdcards
Priority: normal Keywords:

Created on 2020-02-13 12:10 by Andrew Wall, last changed 2020-02-17 09:46 by vstinner.

Messages (3)
msg361953 - (view) Author: Andrew Wall (Andrew Wall) Date: 2020-02-13 12:10
I encountered a question on Stackoverflow where, unusually, a Traceback was given in full, but I couldn't diagnose the problem.

It was like this:

Traceback (most recent call last):
  File "soFailedTraceback.py", line 15, in <module>
    c = C(C1("C1"), C2("C2"))
TypeError: __init__() missing 1 required positional argument: 'p'

What I am claiming is missing is info about class C1:
  File "soFailedTraceback.py", line 8, in <module>
    def __init__(self, s1, p):


Here is the file soFailedTraceback.py:
#soFailedTraceback

class C:
    def __init__(self, c1, p):
        pass

class C1:
    def __init__(self, s1, p):
        pass

class C2:
    def __init__(self, s1):
        pass

c = C(C1("C1"), C2("C2"))

I find the Traceback confusing, because it so happens there are two classes which have required positional argument "p", but python does not directly show which class it is.
msg362040 - (view) Author: szb512 (sdcards) Date: 2020-02-16 00:36
I think it is the "C2" class. Traceback is probably refering to that class.
msg362052 - (view) Author: Ammar Askar (ammar2) * (Python triager) Date: 2020-02-16 08:31
I don't know how common this situation is, the fact that all constructors go to __init__ here makes it a little tough in this case but normally you'd be able to tell by the function name.

One potential solution might be to show which file the error came from like this:

Traceback (most recent call last):
  File "D:\x.py", line 13, in <module>
    c = C(C1("C1"), C2("C2"))
TypeError: [D:\x.py:6] __init__() missing 1 required positional argument: 'p'

This is a pretty trivial change in ceval.c:3779 but might make the errors pretty long unless (especially now that co_filename is an absolute path) we chop them off to just the name of the file.

Including the frame information for the function about to be called would be much more difficult.

Overall this situation might not be worth improving because it's so rare but having the function location in the error might be worth having just as an extra information point.
History
Date User Action Args
2020-02-17 09:46:55vstinnersetnosy: - vstinner
2020-02-16 08:31:53ammar2setnosy: + ammar2
messages: + msg362052
2020-02-16 07:12:29SilentGhostsetnosy: + vstinner

components: + Interpreter Core
versions: + Python 3.9, - Python 3.8
2020-02-16 00:36:19sdcardssetnosy: + sdcards
messages: + msg362040
2020-02-13 12:10:14Andrew Wallcreate