New submission from Dan Snider <mr.assume.a...@gmail.com>:
As far as I know, generators, set comprehensions, list comprehensions, and dict comprehensions, (along with their asynchronous variants) are implemented by first calling the GET_(A)ITER opcode and then building and calling a function that acepts the resulting iterator as its sole argument. Assigning the code object used to make that function (or using it in the types.FunctionType constructor) and then calling it with a non-iterator argument will obviously cause a crash since the FOR_ITER opcode rightly expects that it will never have to deal with non-iterators and calls tp_iternext without checking if it exists. The 4-liner demonstrates the crash: if 1: fn = lambda: None gi = (i for i in ()) fn.__code__ = gi.gi_code [*fn("abc")] ---------- messages: 342797 nosy: bup priority: normal severity: normal status: open title: Calling "functions" used to implement generators/comps easily cause crash type: crash versions: Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36956> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com