Skip to content

map with lambda is broken in Python 2; gives '<Erased>' object is not iterable #5210

Closed

Description

@gvanrossum

@Michael0x2a
This is a regression caused by your PR: f61c2ba Overhaul overload semantics, remove erasure, add union math (#5084).

Example (only works with Python 2 -- it's a syntax error with Python 3):

a = [(1, ''), (2, '')]
b = map(lambda (i, s): str(i) + s, a)

Before that PR, this would pass; now it gives

_.py:2: error: '<Erased>' object is not iterable

Simplifying this further by using a list of ints and a lambda with a non-unpacking argument makes the error going away.

Sorry for being so aggressive with priority etc., this prevents us from using master on our internal code base -- we get a dozen or so of errors due to this. It's not limited to map() -- I see it too for reduce(), imap(), and ifilter(), always with lambda (x, y): ....

Activity

  1. gvanrossum commented on Jun 12, 2018

    @gvanrossum
    MemberAuthor

    Actually I'm not sure if it occurs with ifilter() -- the one occurrence is inside an imap() call:

            owners = imap(lambda (k, v): 'owner=' + k,
                    ifilter(lambda (k, v): v > SET_SIZE_LOW_CUTOFF, count_by_owner.iteritems()))

    All the other functions involved are overloaded. Oh, I also saw an occurrence with max(), which is also overloaded.

  2. gvanrossum commented on Jun 12, 2018

    @gvanrossum
    MemberAuthor

    There's also one occurence of

    '<nothing>' object is not iterable
    

    on a map(None, ...) call -- not a lambda in sight.

    Also, it's not due to the typeshed changes -- I didn't bother changing typeshed when bisecting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions