Re: yield from () Was: Re: weirdness with list()

2021-03-12 Thread Thomas Jollans
On 03/03/2021 01:01, Cameron Simpson wrote: On 02Mar2021 15:06, Larry Martell wrote: I discovered something new (to me) yesterday. Was writing a unit test for generator function and I found that none of the function got executed at all until I iterated on the return value. Aye. Generators are

Friday Finking: following, weirdness with list()

2021-03-11 Thread dn via Python-list
The in-person version of 'Friday Finking' has been set-aside by COVID-precautions. Here's hoping the questions asked below will stimulate some thinking, or mild entertainment... On 02/03/2021 03.10, Grant Edwards wrote: > On 2021-03-01, Greg Ewing wrote: >> On 28/02/21 1:17 pm, Cameron Simpson w

Re: yield from () Was: Re: weirdness with list()

2021-03-11 Thread Chris Angelico
On Fri, Mar 12, 2021 at 8:20 AM Serhiy Storchaka wrote: > > 01.03.21 23:59, Cameron Simpson пише: > > On 28Feb2021 23:47, Alan Gauld wrote: > >> On 28/02/2021 00:17, Cameron Simpson wrote: > >>> BUT... It also has a __iter__ value, which like any Box iterates over > >>> the subboxes. For MDAT tha

Re: yield from () Was: Re: weirdness with list()

2021-03-11 Thread Serhiy Storchaka
01.03.21 23:59, Cameron Simpson пише: > On 28Feb2021 23:47, Alan Gauld wrote: >> On 28/02/2021 00:17, Cameron Simpson wrote: >>> BUT... It also has a __iter__ value, which like any Box iterates over >>> the subboxes. For MDAT that is implemented like this: >>> >>> def __iter__(self): >>>

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Cameron Simpson
On 02Mar2021 15:06, Larry Martell wrote: >I discovered something new (to me) yesterday. Was writing a unit test >for generator function and I found that none of the function got >executed at all until I iterated on the return value. Aye. Generators are lazy - they don't run at all until you ask f

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Larry Martell
On Tue, Mar 2, 2021 at 2:16 PM Chris Angelico wrote: > > On Tue, Mar 2, 2021 at 5:51 AM Alan Gauld via Python-list > wrote: > > > > On 28/02/2021 00:17, Cameron Simpson wrote: > > > > > BUT... It also has a __iter__ value, which like any Box iterates over > > > the subboxes. For MDAT that is impl

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Marco Sulla
On Mon, 1 Mar 2021 at 19:51, Alan Gauld via Python-list wrote: > Sorry, a bit OT but I'm curious. I haven't seen > this before: > > yield from () > > What is it doing? > What do the () represent in this context? It's the empty tuple. -- https://mail.python.org/mailman/listinfo/python-list

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Chris Angelico
On Tue, Mar 2, 2021 at 5:51 AM Alan Gauld via Python-list wrote: > > On 28/02/2021 00:17, Cameron Simpson wrote: > > > BUT... It also has a __iter__ value, which like any Box iterates over > > the subboxes. For MDAT that is implemented like this: > > > > def __iter__(self): > > yield f

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Alan Gauld via Python-list
On 28/02/2021 23:47, Alan Gauld via Python-list wrote: > On 28/02/2021 00:17, Cameron Simpson wrote: > >> BUT... It also has a __iter__ value, which like any Box iterates over >> the subboxes. For MDAT that is implemented like this: >> >> def __iter__(self): >> yield from () > > Sorr

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Chris Angelico
On Wed, Mar 3, 2021 at 8:21 AM Dieter Maurer wrote: > > Alan Gauld wrote at 2021-2-28 23:47 +: > >yield from () > > "yield from iterator" is similar to "for i in iterator: yield i" (with > special handling when data/exceptions are injected into the generator). > > Thus, "yield from ()" does es

yield from () Was: Re: weirdness with list()

2021-03-02 Thread Dieter Maurer
Alan Gauld wrote at 2021-2-28 23:47 +: >yield from () "yield from iterator" is similar to "for i in iterator: yield i" (with special handling when data/exceptions are injected into the generator). Thus, "yield from ()" does essentially nothing with the side effect that the containing function

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Peter Otten
On 01/03/2021 00:47, Alan Gauld via Python-list wrote: On 28/02/2021 00:17, Cameron Simpson wrote: BUT... It also has a __iter__ value, which like any Box iterates over the subboxes. For MDAT that is implemented like this: def __iter__(self): yield from () Sorry, a bit OT but I

Re: weirdness with list()

2021-03-02 Thread Cameron Simpson
On 01Mar2021 14:10, Grant Edwards wrote: >That was certainly my reaction. Can you imagine the confusion if len() >of a list returned the number of bytes required for srorage insttead >of the number of elements? Yeah, well the ancestry of these classes is a binary deserialise/serialise base class

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Cameron Simpson
On 28Feb2021 23:47, Alan Gauld wrote: >On 28/02/2021 00:17, Cameron Simpson wrote: >> BUT... It also has a __iter__ value, which like any Box iterates over >> the subboxes. For MDAT that is implemented like this: >> >> def __iter__(self): >> yield from () > >Sorry, a bit OT but I'm cur

yield from () Was: Re: weirdness with list()

2021-03-01 Thread Alan Gauld via Python-list
On 28/02/2021 00:17, Cameron Simpson wrote: > BUT... It also has a __iter__ value, which like any Box iterates over > the subboxes. For MDAT that is implemented like this: > > def __iter__(self): > yield from () Sorry, a bit OT but I'm curious. I haven't seen this before: yield fro

Re: weirdness with list()

2021-03-01 Thread Grant Edwards
On 2021-03-01, Greg Ewing wrote: > On 28/02/21 1:17 pm, Cameron Simpson wrote: >> [its length in bytes] is presented via the object's __len__ method, > >> BUT... It also has a __iter__ value, which like any Box iterates over >> the subboxes. > > You're misusing __len__ here. If an object is iterab

Re: weirdness with list()

2021-03-01 Thread Cameron Simpson
On 01Mar2021 00:06, MRAB wrote: >I'm not seeing a huge problem here: > >Python 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 >64 bit (AMD64)] on win32 >Type "help", "copyright", "credits" or "license" for more information. import time class A: >... def __len__(self)

Re: weirdness with list()

2021-02-28 Thread Greg Ewing
On 28/02/21 1:17 pm, Cameron Simpson wrote: [its length in bytes] is presented via the object's __len__ method, BUT... It also has a __iter__ value, which like any Box iterates over the subboxes. You're misusing __len__ here. If an object is iterable and also has a __len__, its __len__ shoul

Re: weirdness with list()

2021-02-28 Thread MRAB
On 2021-02-28 23:28, Peter Otten wrote: On 28/02/2021 23:33, Marco Sulla wrote: On Sun, 28 Feb 2021 at 01:19, Cameron Simpson wrote: My object represents an MDAT box in an MP4 file: it is the ludicrously large data box containing the raw audiovideo data; for a TV episode it is often about 2GB

Re: weirdness with list()

2021-02-28 Thread Cameron Simpson
On 01Mar2021 00:28, Peter Otten <__pete...@web.de> wrote: >On 28/02/2021 23:33, Marco Sulla wrote: >>I can't reproduce, Am I missing something? >> >>marco@buzz:~$ python3 >>Python 3.6.9 (default, Jan 26 2021, 15:33:00) >>[GCC 8.4.0] on linux >>Type "help", "copyright", "credits" or "license" for mo

Re: weirdness with list()

2021-02-28 Thread Cameron Simpson
On 28Feb2021 10:51, Peter Otten <__pete...@web.de> wrote: >On 28/02/2021 01:17, Cameron Simpson wrote: >>I noticed that it was stalling, and investigation revealed it was >>stalling at this line: >> >> subboxes = list(self) >> >>when doing the MDAT box. That box (a) has no subboxes at all and (

Re: weirdness with list()

2021-02-28 Thread Peter Otten
On 28/02/2021 23:33, Marco Sulla wrote: On Sun, 28 Feb 2021 at 01:19, Cameron Simpson wrote: My object represents an MDAT box in an MP4 file: it is the ludicrously large data box containing the raw audiovideo data; for a TV episode it is often about 2GB and a movie is often 4GB to 6GB. [...] Th

Re: weirdness with list()

2021-02-28 Thread Marco Sulla
On Sun, 28 Feb 2021 at 01:19, Cameron Simpson wrote: > My object represents an MDAT box in an MP4 file: it is the ludicrously > large data box containing the raw audiovideo data; for a TV episode it > is often about 2GB and a movie is often 4GB to 6GB. > [...] > That length is presented via the ob

Re: weirdness with list()

2021-02-28 Thread Peter Otten
On 28/02/2021 01:17, Cameron Simpson wrote: I just ran into a surprising (to me) issue with list() on an iterable object. My object represents an MDAT box in an MP4 file: it is the ludicrously large data box containing the raw audiovideo data; for a TV episode it is often about 2GB and a movie i

weirdness with list()

2021-02-27 Thread Cameron Simpson
I just ran into a surprising (to me) issue with list() on an iterable object. My object represents an MDAT box in an MP4 file: it is the ludicrously large data box containing the raw audiovideo data; for a TV episode it is often about 2GB and a movie is often 4GB to 6GB. For obvious reasons, I