[Python-Dev] PEP 340: Deterministic Finalisation (new PEP draft, either a competitor or update to PEP 340)

Josiah Carlson jcarlson at uci.edu
Sun May 8 06:21:47 CEST 2005


Ron Adam <rrr at ronadam.com> wrote:
> Josiah Carlson wrote:
> 
>  > You should know why that can't work.  If I pass a list, is a list an
>  > iterator?  No, but it should neither be created nor destroyed before or
>  > after.
>  >
>  > The discussion has been had in regards to why re-using 'for' is a
>  > non-starter; re-read the 200+ messages in the thread.
>  >
>  >  - Josiah
> 
> 
> I agree, re-using or extending 'for' doesn't seem like a good idea to me.

Now that I've actually stopped to read Nick's PEP, my concern is that
'del', while being a keyword, would not be easy to spot embedded in the
rest of the line, and a large number of these 'statements' will only be
executed once, so the 'for' may confuse people.


> I wonder how much effect adding, 'for-next' and the 'StopIteration' 
> exception check as proposed in PEP340, will have on 'for''s performance.

For is already tuned to be as fast as possible, which makes sense; it is
used 4,523 times in Python 2.4.0's standard library, and easily hundreds
of thousands of times in user code.  Changing the standard for loop is
not to be done lightly.


> And why this isn't just as good:
> 
>      try:
>          for value in iterator:
>              BLOCK1
>      except StopIteration:
>          BLOCK2
> 
> Is one extra line that bad?

I don't know what line you are referring to.

> I think a completely separate looping or non-looping construct would be 
> better for the finalization issue, and maybe can work with class's with 
> __exit__ as well as generators.

From what I understand, the entire conversation has always stated that
class-based finalized objects and generator-based finalized objects will
both work, and that any proposal that works for one, but not the other,
is not sufficient.


> Having it loop has the advantage of making it break out in a better 
> behaved way.

What you have just typed is nonsense.  Re-type it and be explicit.


> Hint: 'do'

'do' has been previously mentioned in the thread.

 - Josiah



More information about the Python-Dev mailing list