Bug in inspect.py for python 2.3?

Discussion in 'Python' started by Fernando Perez, Dec 17, 2004.

  1. Hi all,

    IPython has suffered quite a few problems with the inspect module in python
    2.3. For these, unfortunately all I've been able to do is guard with
    overreaching except clauses, as I had not been able to find small,
    reproducible examples to pass on to the devs. But today I got a crash report
    from a user and I've been able to replicate this crash with a tiny script
    which does not depend on ipython at all.

    I'd like to hear from some of our resident gurus if this is really an
    inspect.py bug before I bother the developers with a formal bug report on SF.
    The script below illustrates the problem. Just run it, and you'll get a
    traceback coming from inside inspect.py itself. For now, I've added a guard
    in ipython against this failure mode, but it would be nice to fix the problem
    at the source if there really is one.

    Best,

    f


    #!/usr/bin/env python
    """This script triggers an exception in inspect.py

    This exception was crashing ipython for the input line:

    (lambda(x): x[0] + x[1])(3)

    when IPython tried to print the traceback for the user. As far as I can tell,
    it's a bug in inspect, since for all other kinds of calls of invalid user
    input, ipython works fine. But perhaps it's my fault, I'm not sure."""

    import sys
    import inspect

    try:
    # This line is invalid, but we should be able to build exception info for
    # it with the usual tools.
    (lambda(x): x[0] + x[1])(3)
    except:
    etb = sys.exc_info()[2]
    records = inspect.getinnerframes(etb)

    for frame, file, lnum, func, lines, index in records:

    # The getargvalues call below blows up with an exception in inspect.py
    args, varargs, varkw, locals = inspect.getargvalues(frame)

    print 'args:',args
    Fernando Perez, Dec 17, 2004
    #1
    1. Advertising

  2. Fernando Perez

    Peter Otten Guest

    Fernando Perez wrote:

    > IPython has suffered quite a few problems with the inspect module in
    > python
    > 2.3. For these, unfortunately all I've been able to do is guard with
    > overreaching except clauses, as I had not been able to find small,
    > reproducible examples to pass on to the devs. But today I got a crash
    > report from a user and I've been able to replicate this crash with a tiny
    > script which does not depend on ipython at all.
    >
    > I'd like to hear from some of our resident gurus if this is really an
    > inspect.py bug before I bother the developers with a formal bug report on
    > SF.
    > The script below illustrates the problem. Just run it, and you'll get a
    > traceback coming from inside inspect.py itself. For now, I've added a
    > guard in ipython against this failure mode, but it would be nice to fix
    > the problem at the source if there really is one.


    That is indeed a bug, and it is fixed as of
    http://sourceforge.net/tracker/index.php?func=detail&aid=1005466&group_id=5470&atid=305470

    Minimal example:

    [Python 2.3.3]
    >>> def f(a): pass

    ....
    >>> def g((a)): pass

    ....
    >>> inspect.getargs(f.func_code)

    (['a'], None, None)
    >>> inspect.getargs(g.func_code)

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "/usr/lib/python2.3/inspect.py", line 624, in getargs
    remain[-1] = remain[-1] - 1
    IndexError: list index out of range

    [Python 2.4]
    >>> import inspect
    >>> def g((a)): pass

    ....
    >>> inspect.getargs(g.func_code)

    ([['a']], None, None)


    By the way, I didn't know that sublists of length one are allowed in a
    function's parameter list. Certainly they don't make much sense...

    Peter
    Peter Otten, Dec 18, 2004
    #2
    1. Advertising

  3. Peter Otten wrote:

    > Fernando Perez wrote:
    >


    >> I'd like to hear from some of our resident gurus if this is really an
    >> inspect.py bug before I bother the developers with a formal bug report on
    >> SF.
    >> The script below illustrates the problem. Just run it, and you'll get a
    >> traceback coming from inside inspect.py itself. For now, I've added a
    >> guard in ipython against this failure mode, but it would be nice to fix
    >> the problem at the source if there really is one.

    >
    > That is indeed a bug, and it is fixed as of
    >

    http://sourceforge.net/tracker/index.php?func=detail&aid=1005466&group_id=5470&atid=305470

    Great, many thanks for the info. This way I don't bother the devs with
    unnecessary bug triage.

    Regards,

    f
    Fernando Perez, Dec 18, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robin Becker

    bug in inspect (was cgitb vs traceback)

    Robin Becker, Jun 6, 2004, in forum: Python
    Replies:
    1
    Views:
    296
    Robin Becker
    Jun 6, 2004
  2. Stef Mientki

    Would this be called a bug in inspect ?

    Stef Mientki, Sep 30, 2008, in forum: Python
    Replies:
    0
    Views:
    232
    Stef Mientki
    Sep 30, 2008
  3. Aaron \Castironpi\ Brady

    inspect bug

    Aaron \Castironpi\ Brady, Oct 9, 2008, in forum: Python
    Replies:
    3
    Views:
    363
    Terry Reedy
    Oct 9, 2008
  4. inhahe
    Replies:
    5
    Views:
    392
    Peter Decker
    Jan 2, 2010
  5. deluxstar
    Replies:
    5
    Views:
    864
    Terry Reedy
    Sep 25, 2010
Loading...

Share This Page