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: KeyError with cgitb inspecting exception in generator expression
Type: Stage: resolved
Components: Interpreter Core, Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, jaraco
Priority: normal Keywords:

Created on 2017-07-13 20:46 by jaraco, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg298314 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2017-07-13 20:46
Consider this script, which runs successfully on Python 3:

import cgitb
import sys


def fiter():
    assert False
    yield 1, 1
    yield 2, 2
    yield 3, 3


try:
    x = set(id_ for id_, _ in fiter())
except:
    print cgitb.html(sys.exc_info())


Run the same script on Python 2.7.13 and you get this error:

Traceback (most recent call last):
  File "test.py", line 15, in <module>
    print(cgitb.html(sys.exc_info()))
  File ".../cgitb.py", line 130, in html
    formatvalue=lambda value: '=' + pydoc.html.repr(value))
  File ".../inspect.py", line 887, in formatargvalues
    specs.append(strseq(args[i], convert, join))
  File ".../inspect.py", line 840, in strseq
    return join(map(lambda o, c=convert, j=join: strseq(o, c, j), object))
  File ".../inspect.py", line 840, in <lambda>
    return join(map(lambda o, c=convert, j=join: strseq(o, c, j), object))
  File ".../inspect.py", line 842, in strseq
    return convert(object)
  File ".../inspect.py", line 884, in convert
    return formatarg(name) + formatvalue(locals[name])
KeyError: 'id_'


Wrap the generator expression in [] and it also succeeds.

Given that the issue only exists on Python 2.7, it may not need to be addressed, but I wanted to log the issue nonetheless.
msg376182 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2020-09-01 08:15
Python 2.7 is no longer supported, so I think this issue should be closed.
History
Date User Action Args
2022-04-11 14:58:49adminsetgithub: 75109
2020-09-01 13:20:29jaracosetstatus: open -> closed
resolution: wont fix
stage: resolved
2020-09-01 08:15:35ZackerySpytzsetnosy: + ZackerySpytz
messages: + msg376182
2017-07-13 20:46:43jaracocreate