Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yield expression vs lambda #48998

Closed
birkenfeld opened this issue Dec 26, 2008 · 6 comments
Closed

yield expression vs lambda #48998

birkenfeld opened this issue Dec 26, 2008 · 6 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@birkenfeld
Copy link
Member

BPO 4748
Nosy @birkenfeld, @benjaminp
Files
  • nasty_lambda_generators.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-12-27.18:24:29.789>
    created_at = <Date 2008-12-26.09:57:38.882>
    labels = ['type-bug']
    title = 'yield expression vs lambda'
    updated_at = <Date 2008-12-27.18:24:29.788>
    user = 'https://github.com/birkenfeld'

    bugs.python.org fields:

    activity = <Date 2008-12-27.18:24:29.788>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-12-27.18:24:29.789>
    closer = 'benjamin.peterson'
    components = []
    creation = <Date 2008-12-26.09:57:38.882>
    creator = 'georg.brandl'
    dependencies = []
    files = ['12467']
    hgrepos = []
    issue_num = 4748
    keywords = ['patch', 'needs review']
    message_count = 6.0
    messages = ['78291', '78332', '78370', '78373', '78374', '78377']
    nosy_count = 2.0
    nosy_names = ['georg.brandl', 'benjamin.peterson']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4748'
    versions = ['Python 2.6', 'Python 3.0']

    @birkenfeld
    Copy link
    Member Author

    With lambda, the ban on "return x" in generators can be evaded:

    >>> x = lambda: ((yield 1), (yield 2))
    >>> list(x())
    [1, 2, (None, None)]
    >>> dis.dis(x)
      1           0 LOAD_CONST               0 (1)
                  3 YIELD_VALUE
                  4 LOAD_CONST               1 (2)
                  7 YIELD_VALUE
                  8 BUILD_TUPLE              2
                 11 RETURN_VALUE

    @benjaminp
    Copy link
    Contributor

    Attaching patch?

    BTW, how did you find this bug? :)

    @benjaminp benjaminp added the type-bug An unexpected behavior, bug, or error label Dec 27, 2008
    @birkenfeld
    Copy link
    Member Author

    I didn't find it, but someone from the German Python webforum. :)

    Hmm, I wonder why lambda: (yield 1) alone doesn't give [1, None]. (That
    should also go into the test case.)

    Anyway, perhaps yield in lambdas should be forbidden.

    @benjaminp
    Copy link
    Contributor

    On Sat, Dec 27, 2008 at 11:41 AM, Georg Brandl <report@bugs.python.org> wrote:

    Georg Brandl <georg@python.org> added the comment:

    I didn't find it, but someone from the German Python webforum. :)

    Hmm, I wonder why lambda: (yield 1) alone doesn't give [1, None]. (That
    should also go into the test case.)

    Actually, I don't think the return value should even make it's way to
    the list. Generator lambdas shouldn't have any return value IMO.

    Anyway, perhaps yield in lambdas should be forbidden.

    Probably too late now for 2.x and 3.x.

    @birkenfeld
    Copy link
    Member Author

    > Hmm, I wonder why lambda: (yield 1) alone doesn't give [1, None]. (That
    > should also go into the test case.)

    Actually, I don't think the return value should even make it's way to
    the list. Generator lambdas shouldn't have any return value IMO.

    Yes, I think so too. I just wondered at the seemingly inconsistent
    behavior right now.

    > Anyway, perhaps yield in lambdas should be forbidden.

    Probably too late now for 2.x and 3.x.

    Right. I'd say go for applying the patch.

    @benjaminp
    Copy link
    Contributor

    Fixed in r67954.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants