[Python-ideas] __len__() for map()

E. Madison Bray erik.m.bray at gmail.com
Wed Nov 28 10:18:35 EST 2018


On Wed, Nov 28, 2018 at 4:14 PM Steven D'Aprano <steve at pearwood.info> wrote:
>
> On Wed, Nov 28, 2018 at 04:04:33PM +0100, E. Madison Bray wrote:
>
> > That effort is already mostly done and adding a helper function would
> > not have worked as users *passing* map(...) as an argument to some
> > function just expect it to work.
>
> Ah, that's what I was missing.
>
> But... surely the function will still work if they pass an opaque
> iterator *other* than map() and/or filter?
>
> it = (func(x) for x in something if condition(x))
> some_sage_function(it)

That one is admittedly tricky.  For that matter it might be nice to
have more introspection of generator expressions too, but there at
least we have .gi_code if nothing else.

But those are a far less common example in my case, whereas map() is
*everywhere* in math code :)


More information about the Python-ideas mailing list