This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Unhandled exceptions in pdb return value display
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, Simon.Chopin, georg.brandl, terry.reedy, tshepang, xdegaye
Priority: normal Keywords:

Created on 2012-03-05 00:15 by Simon.Chopin, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg154916 - (view) Author: Simon Chopin (Simon.Chopin) Date: 2012-03-05 00:15
This issue occurred at least in Python 2.7, I haven't checked in other versions.

When stepping on a return statement, pdb calls the return value __str__() method to display it at the end of the line. Only, it doesn't handle the potential exceptions raised within those functions.

An exemple would be:
import pdb

class A(object):
    def __new__(cls):
        pdb.set_trace()
        return super(A, cls).__new__()
    def __init__(self):
        self.value = "Foo"
    def __str__(self):
        return self.value

pdb.run("A()")

When using the step by step, pdb will be interrupted by an unhandled AttributeError.
msg175294 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2012-11-10 20:25
I cannot reproduce the problem on python 2.7.  The example runs
without problem after fixing the example with the
following changes:

    remove the call to pdb.set_trace(), the debugger is already
    started with a call to pdb.run()

    add the missing 'cls' parameter in the call to __new__() in:
        return super(A, cls).__new__()
msg266260 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-05-24 18:54
Georg, if you agree that Xavier's analysis is correct, we can close this as not a bug.
msg355634 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-10-29 09:34
Can't reproducible in py3 (3.8), IMHO can be closed.
msg355665 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-10-29 18:12
Batuhan, thanks for the nudge.  For the record ...

If __new__ were a normal instance method, then 'some_class.__new__()' would be a correct call, as 'some_class' would be passed to '__new__' as its first and perhaps only argument.  But " __new__() is a static method (special-cased so you need not declare it as such)".
https://docs.python.org/3/reference/datamodel.html#object.__new__
Its special-casing makes it easy to forget that its first argument, a class, must be passed explicitly.  Hence Xavier's comment.

In current 2.7.17 and 3.8 (for instance), with pdb left out of the picture, the missing cls argument results in
  TypeError: object.__new__(): not enough arguments

When I pdb.run('A()') new and step, it catches the error and refuses to advance.

> <pyshell#10>(3)__new__()
(Pdb) s
TypeError: object.__new__(): not enough arguments
> <pyshell#10>(3)__new__()
History
Date User Action Args
2022-04-11 14:57:27adminsetgithub: 58404
2019-10-29 18:12:48terry.reedysetstatus: open -> closed
type: behavior
messages: + msg355665

resolution: not a bug
stage: resolved
2019-10-29 09:34:31BTaskayasetnosy: + BTaskaya
messages: + msg355634
2016-05-24 18:54:52terry.reedysetnosy: + georg.brandl, terry.reedy
messages: + msg266260
2012-11-10 20:25:05xdegayesetnosy: + xdegaye
messages: + msg175294
2012-03-06 10:11:29tshepangsetnosy: + tshepang
2012-03-05 00:15:16Simon.Chopincreate