Message 342797 - Python tracker

Message342797

Author bup
Recipients bup
Date 2019-05-18.13:53:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1558187601.17.0.878025070628.issue36956@roundup.psfhosted.org>
In-reply-to
Content
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")]
History
Date User Action Args
2019-05-18 13:53:21bupsetrecipients: + bup
2019-05-18 13:53:21bupsetmessageid: <1558187601.17.0.878025070628.issue36956@roundup.psfhosted.org>
2019-05-18 13:53:21buplinkissue36956 messages
2019-05-18 13:53:20bupcreate