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

2018-11-29 Thread Abe Dillon
That would be great especially if it returned objects of a subclass of map so that it didn't break any code that checks isinstance, however; I think this goes a little beyond map. I've run into cases using itertools where I wished the iterators could support len. I suppose you could turn those all

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

2018-11-29 Thread Paul Svensson
On Mon, Nov 26, 2018 at 10:35 PM Kale Kundert wrote: I just ran into the following behavior, and found it surprising: len(map(float, [1,2,3])) TypeError: object of type 'map' has no len() I understand that map() could be given an infinite sequence and therefore might not always have a leng

[Python-ideas] [off-topic?] Unwinding generators

2018-11-29 Thread Juancarlo Añez
This is code from the Twisted library: https://github.com/twisted/twisted/blob/trunk/src/twisted/internet/defer.py#L1542-L1614 It "unwinds" a generator to yield a result before others. I don't have hard evidence, but my experience is that that kind of manipulation leaks resources, specially if e

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

2018-11-29 Thread Abe Dillon
[David Mertz] > Do you anticipate that the `len()` function will be able to solve the > Halting Problem? > It is simply not possible to know whether a given iterator will produce > finitely many or infinitely many elements. Even those that will produce > finitely many do not, in general, have a

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

2018-11-29 Thread Terry Reedy
On 11/29/2018 8:16 AM, E. Madison Bray wrote: Okay, let's keep it simple: m = map(str, [1, 2, 3]) len_of_m = None if len(m.iters) == 1 and isinstance(m.iters[0], Sized): len_of_m = len(m.iters[0]) As I have noted before, the existing sized collection __length_hint__ methods (properly) r

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

2018-11-29 Thread Terry Reedy
On 11/29/2018 6:13 AM, E. Madison Bray wrote: On Wed, Nov 28, 2018 at 8:54 PM Terry Reedy wrote: The CPython map() implementation already carries this data on it as "func" and "iters" members in its struct. It's trivial to expose those to Python as ".funcs" and ".iters" attributes. Nothing

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

2018-11-29 Thread Jonathan Fine
On Thu, Nov 29, 2018 at 2:44 PM Steven D'Aprano wrote: > You might say that your users are not so advanced, or that they're naive > enough not to even know they could do that, but that's a pretty unsafe > assumption as well as being rather insulting to your own users, some of > whom are surely ad

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

2018-11-29 Thread Adrien Ricocotam
Alright, I didn’t see those problem. Though I was suggesting that for functions like map, we just let the used iterator answer, this is interesting. Thanks for this On Thu 29 Nov 2018 at 17:40, David Mertz wrote: > On Thu, Nov 29, 2018 at 2:29 AM Adrien Ricocotam > wrote: > >> Some suggested ab

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

2018-11-29 Thread David Mertz
On Thu, Nov 29, 2018 at 2:29 AM Adrien Ricocotam wrote: > Some suggested above to change the definition of len in the long term. > Then I think it could be interesting to define len such as : > > - If has a finite length : return that length (the way it works now) > - If has a length that is inf

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

2018-11-29 Thread E. Madison Bray
On Thu, Nov 29, 2018 at 3:43 PM Steven D'Aprano wrote: > > On Thu, Nov 29, 2018 at 02:16:48PM +0100, E. Madison Bray wrote: > > > Okay, let's keep it simple: > > > > m = map(str, [1, 2, 3]) > > len_of_m = None > > if len(m.iters) == 1 and isinstance(m.iters[0], Sized): > > len_of_m = len(m.ite

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

2018-11-29 Thread Steven D'Aprano
On Thu, Nov 29, 2018 at 02:16:48PM +0100, E. Madison Bray wrote: > Okay, let's keep it simple: > > m = map(str, [1, 2, 3]) > len_of_m = None > if len(m.iters) == 1 and isinstance(m.iters[0], Sized): > len_of_m = len(m.iters[0]) > > You can give me pathological cases where that isn't true, bu

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

2018-11-29 Thread Jonathan Fine
On Thu, Nov 29, 2018 at 2:05 PM E. Madison Bray wrote: > The users--often scientists--of SageMath and many other scientific > Python packages* are not "Python programmers" as such**. My job as a > software engineer is to make the lower-level libraries they use for > their day-to-day research wor

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

2018-11-29 Thread E. Madison Bray
On Thu, Nov 29, 2018 at 2:22 PM Chris Angelico wrote: > > On Fri, Nov 30, 2018 at 12:18 AM Steven D'Aprano wrote: > > Sage wraps a number of Python libraries, such as numpy, sympy and > > others, and itself can run under iPython which for all we know may > > already have monkeypatched the builtin

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

2018-11-29 Thread Chris Angelico
On Fri, Nov 30, 2018 at 12:18 AM Steven D'Aprano wrote: > Sage wraps a number of Python libraries, such as numpy, sympy and > others, and itself can run under iPython which for all we know may > already have monkeypatched the builtins for its own ~~nefarious~~ useful > purposes. Are you really com

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

2018-11-29 Thread Steven D'Aprano
On Thu, Nov 29, 2018 at 10:21:15PM +1100, Chris Angelico wrote: > On Thu, Nov 29, 2018 at 10:18 PM E. Madison Bray > wrote: > > > > On Thu, Nov 29, 2018 at 12:16 PM Chris Angelico wrote: > > > > > > On Thu, Nov 29, 2018 at 10:14 PM E. Madison Bray > > > wrote: [...] > > > If that's the case, t

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

2018-11-29 Thread E. Madison Bray
On Thu, Nov 29, 2018 at 1:38 PM Steven D'Aprano wrote: > > On Thu, Nov 29, 2018 at 12:16:37PM +0100, E. Madison Bray wrote: > > On Wed, Nov 28, 2018 at 11:27 PM Steven D'Aprano > > wrote: > > ["it" below being the length of an arbitrary iterator] > > > > If we could solve it, that would be great

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

2018-11-29 Thread E. Madison Bray
On Thu, Nov 29, 2018 at 12:21 PM Chris Angelico wrote: > > On Thu, Nov 29, 2018 at 10:18 PM E. Madison Bray > wrote: > > > > On Thu, Nov 29, 2018 at 12:16 PM Chris Angelico wrote: > > > > > > On Thu, Nov 29, 2018 at 10:14 PM E. Madison Bray > > > wrote: > > > > P.S. > > > > > > > > > > This i

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

2018-11-29 Thread Steven D'Aprano
On Thu, Nov 29, 2018 at 12:16:37PM +0100, E. Madison Bray wrote: > On Wed, Nov 28, 2018 at 11:27 PM Steven D'Aprano wrote: ["it" below being the length of an arbitrary iterator] > > If we could solve it, that would be great -- but I'm not convinced that > > it is solvable, since the solution see

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

2018-11-29 Thread Chris Angelico
On Thu, Nov 29, 2018 at 10:18 PM E. Madison Bray wrote: > > On Thu, Nov 29, 2018 at 12:16 PM Chris Angelico wrote: > > > > On Thu, Nov 29, 2018 at 10:14 PM E. Madison Bray > > wrote: > > > P.S. > > > > > > > > This is necessary because if I have a function that used to take, say, > > > > > a li

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

2018-11-29 Thread E. Madison Bray
On Thu, Nov 29, 2018 at 12:16 PM Chris Angelico wrote: > > On Thu, Nov 29, 2018 at 10:14 PM E. Madison Bray > 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

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

2018-11-29 Thread E. Madison Bray
On Wed, Nov 28, 2018 at 11:27 PM Steven D'Aprano wrote: > > On Wed, Nov 28, 2018 at 02:53:50PM -0500, Terry Reedy wrote: > > What makes the map class special among all built-in iterator classes? > > It appears not to be a property of the class itself, as an iterator > > class, but of its name. In

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

2018-11-29 Thread Chris Angelico
On Thu, Nov 29, 2018 at 10:14 PM E. Madison Bray 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 requiri

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

2018-11-29 Thread E. Madison Bray
On Wed, Nov 28, 2018 at 8:54 PM Terry Reedy wrote: > > On 11/28/2018 9:27 AM, E. Madison Bray wrote: > > On Mon, Nov 26, 2018 at 10:35 PM Kale Kundert wrote: > >> > >> I just ran into the following behavior, and found it surprising: > >> > > len(map(float, [1,2,3])) > >> TypeError: object of

Re: [Python-ideas] [Brainstorm] Testing with Documented ABCs

2018-11-29 Thread Antoine Pitrou
On Wed, 28 Nov 2018 23:22:20 -0200 Marcos Eliziario wrote: > But nobody is talking about exhausting the combinatoric space of all > possible values. Property Based Testing looks like Fuzzy Testing but it is > not quite the same thing. Well, the OP did talk about "exhaustively searching the multi

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

2018-11-29 Thread E. Madison Bray
On Wed, Nov 28, 2018 at 11:04 PM Steven D'Aprano wrote: > > On Wed, Nov 28, 2018 at 05:37:39PM +0100, Anders Hovmöller wrote: > > > > > > > I just mentioned that porting effort for background. I still believe > > > that the actual proposal of making the arguments to a map(...) call > > > accessib

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

2018-11-29 Thread E. Madison Bray
On Wed, Nov 28, 2018 at 11:59 PM Greg Ewing wrote: > > E. Madison Bray wrote: > > So I might want to check: > > > > finite_definite = True > > for it in my_map.iters: > > try: > > len(it) > > except TypeError: > > finite_definite = False > > > > if finite_definite: > >

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

2018-11-29 Thread Terry Reedy
On 11/28/2018 5:27 PM, Steven D'Aprano wrote: On Wed, Nov 28, 2018 at 02:53:50PM -0500, Terry Reedy wrote: One of the guidelines in the Zen of Python is "Special cases aren't special enough to break the rules." This proposal claims that the Python 3 built-in iterator class 'map' is so special