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

Chris Angelico rosuav at gmail.com
Thu Nov 29 06:21:15 EST 2018


On Thu, Nov 29, 2018 at 10:18 PM E. Madison Bray <erik.m.bray at gmail.com> wrote:
>
> On Thu, Nov 29, 2018 at 12:16 PM Chris Angelico <rosuav at gmail.com> wrote:
> >
> > On Thu, Nov 29, 2018 at 10:14 PM E. Madison Bray <erik.m.bray at gmail.com> wrote:
> > > P.S.
> > >
> > > > > This is necessary because if I have a function that used to take, say,
> > > > > a list as an argument, and it receives a `map` object, I now have to
> > > > > be able to deal with map()s,
> > > >
> > > > If a function is documented as requiring a list, or a sequence, or a
> > > > length object, it is a user bug to pass an iterator.  The only thing
> > > > special about map and filter as errors is the rebinding of the names
> > > > between Py2 and Py3, so that the same code may be good in 2.x and bad in
> > > > 3.x.
> > >
> > > It's not a user bug if you're porting a massive computer algebra
> > > application that happens to use Python as its implementation language
> > > (rather than inventing one from scratch) and your users don't need or
> > > want to know too much about Python 2 vs Python 3.  Besides, the fact
> > > that they are passing an iterator now is probably in many cases a good
> > > thing for them, but it takes away my ability as a developer to find
> > > out more about what they're trying to do, as opposed to say just being
> > > given a list of finite size.
> >
> > If that's the case, then it should be no problem to rebind
> > builtins.map to return a list. Problem solved.
>
> Rebind where?  How?  In sage.__init__?  How do you think that will fly
> with other packages loaded in the same interpreter?

Either this is Python, or it's just an algebra language that happens
to be implemented in Python. If the former, the Py2/Py3 distinction
should matter to your users, since they are programming in Python. If
the latter, it's all about Sage, ergo you can rebind map to mean what
you expect it to mean. Take your pick.

ChrisA


More information about the Python-ideas mailing list