Re: Lifetime of a local reference

2019-03-01 Thread Gregory Ewing
Alan Bawden wrote: The Java compiler has no way to know whether a variable references an object with a finalize() method that has side effects It should be able to tell in some situations, e.g. String a = "hello"; String b = a.replace('e', 'u'); There's no way that b can reference

Re: Lifetime of a local reference

2019-03-01 Thread Alan Bawden
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Alan Bawden writes: > >The Java compiler has no way to know whether a variable references an > >object with a finalize() method that has side effects > > java.lang.Object#finalize() is deprecated since Java 9. And we are advised to use a

Re: Lifetime of a local reference

2019-02-28 Thread Chris Angelico
On Fri, Mar 1, 2019 at 9:31 AM Marko Rauhamaa wrote: > > Roel Schroeven : > > In the absence of any other mention of bindings being removed, to me > > it seems clear that bindings are not automatically removed. Otherwise > > many things become ambiguous. Example: the documentation for dicts > >

Re: Lifetime of a local reference

2019-02-28 Thread Marko Rauhamaa
Roel Schroeven : > In the absence of any other mention of bindings being removed, to me > it seems clear that bindings are not automatically removed. Otherwise > many things become ambiguous. Example: the documentation for dicts > defines "d[key] = value" as "Set d[key] to value". Does that mean

Re: Lifetime of a local reference

2019-02-28 Thread Roel Schroeven
Rhodri James schreef op 28/02/2019 om 13:09: On 27/02/2019 21:39, Roel Schroeven wrote: Rhodri James schreef op 27/02/2019 om 15:18: Aren't we overthinking this? I think it's pretty clear that a variable is never deleted before it goes out of scope. A quick search in the documentation points

Re: Lifetime of a local reference

2019-02-28 Thread Marko Rauhamaa
Chris Angelico : > What if an exception gets raised at some point before the function has > returned? The exception object will give full access to the function's > locals. It wouldn't hurt for the Python gods to make an explicit ruling on the matter. Marko --

Re: Lifetime of a local reference

2019-02-28 Thread Chris Angelico
On Thu, Feb 28, 2019 at 11:13 PM Rhodri James wrote: > > On 27/02/2019 21:39, Roel Schroeven wrote: > > Rhodri James schreef op 27/02/2019 om 15:18: > > Aren't we overthinking this? > > > > I think it's pretty clear that a variable is never deleted before it > > goes out of scope. A quick search

Re: Lifetime of a local reference

2019-02-28 Thread Rhodri James
On 27/02/2019 21:39, Roel Schroeven wrote: Rhodri James schreef op 27/02/2019 om 15:18: Aren't we overthinking this? I think it's pretty clear that a variable is never deleted before it goes out of scope. A quick search in the documentation points me to

Re: Lifetime of a local reference

2019-02-28 Thread Marko Rauhamaa
Alan Bawden : > Gregory Ewing writes: > >> Alan Bawden wrote: >> > the Java Language >> > Specification contains the following language: >> >Optimizing transformations of a program can be designed that reduce >> >the number of objects that are reachable to be less than those which >> >

Re: Lifetime of a local reference

2019-02-27 Thread Alan Bawden
Gregory Ewing writes: > Alan Bawden wrote: > > the Java Language > > Specification contains the following language: > >Optimizing transformations of a program can be designed that reduce > >the number of objects that are reachable to be less than those which > >would naively be

Re: Lifetime of a local reference

2019-02-27 Thread Gregory Ewing
Thomas Jollans wrote: If the inspect module's stack frame inspection machinery is supported, then any function call might access any local... (though I don't think a compliant Python implementation necessarily has to support the inspect module fully). You can be devious even without using the

Re: Lifetime of a local reference

2019-02-27 Thread Gregory Ewing
Alan Bawden wrote: the Java Language Specification contains the following language: Optimizing transformations of a program can be designed that reduce the number of objects that are reachable to be less than those which would naively be considered reachable. For example, a Java

Re: Lifetime of a local reference

2019-02-27 Thread Thomas Jollans
On 27/02/2019 22:39, Roel Schroeven wrote: > Aren't we overthinking this? No, it's just that nobody had found the evidence you did. > > I think it's pretty clear that a variable is never deleted before it > goes out of scope. A quick search in the documentation points me to >

Re: Lifetime of a local reference

2019-02-27 Thread Roel Schroeven
Rhodri James schreef op 27/02/2019 om 15:18: On 27/02/2019 06:56, Marko Rauhamaa wrote: Alan Bawden : But I appreciate that that isn't the true question that you wanted to ask! You are wondering if a Python implementation is _permitted_ to treat the code you wrote _as if_ you had written:

Re: Lifetime of a local reference

2019-02-27 Thread Thomas Jollans
On 27/02/2019 16.41, Marko Rauhamaa wrote: > Rhodri James : >> The description of the with statement does explicitly say that the >> context manager's __exit__() method won't be called until the suite >> has been executed, so the reference to the open file must exist for at >> least that long. >

Re: Lifetime of a local reference

2019-02-27 Thread Marko Rauhamaa
Rhodri James : > On 27/02/2019 06:56, Marko Rauhamaa wrote: >> Then there's the question of a sufficient way to prevent premature >> garbage collection: >> >> def fun(): >> f = open("lock") >> flock.flock(f, fcntl.LOCK_EX) >> do_stuff() >> f.close() >>

Re: Lifetime of a local reference

2019-02-27 Thread Rhodri James
On 27/02/2019 06:56, Marko Rauhamaa wrote: Alan Bawden : But I appreciate that that isn't the true question that you wanted to ask! You are wondering if a Python implementation is _permitted_ to treat the code you wrote _as if_ you had written: def fun(): f = open("lock")

Re: Lifetime of a local reference

2019-02-27 Thread Thomas Jollans
On 27/02/2019 04.14, Alan Bawden wrote: > Marko Rauhamaa writes: >> I couldn't find an immediate answer in the documentation. > > I suspect that given the history of Python, pretty much everybody has > always assumed that a Python implementation will not delete local variables > early. But I

Re: Lifetime of a local reference

2019-02-27 Thread Test Bot
Just to add on regarding file I/O. It would be more pythonic to use. with open(path): do_stuff() On Wed, Feb 27, 2019, 3:31 AM Marko Rauhamaa wrote: > > Consider this function: > > def fun(): > f = open("lock") > flock.flock(f, fcntl.LOCK_EX) > do_stuff() >

Re: Lifetime of a local reference

2019-02-26 Thread Marko Rauhamaa
Alan Bawden : > Marko Rauhamaa writes: >> def fun(): >> f = open("lock") >> flock.flock(f, fcntl.LOCK_EX) >> do_stuff() >> sys.exit(0) >> >> Question: can a compliant Python implementation close f (and, >> consequently, release the file lock) before/while

Re: Lifetime of a local reference

2019-02-26 Thread Alan Bawden
Marko Rauhamaa writes: > def fun(): > f = open("lock") > flock.flock(f, fcntl.LOCK_EX) > do_stuff() > sys.exit(0) > > Question: can a compliant Python implementation close f (and, > consequently, release the file lock) before/while do_stuff() is > executed? A

Re: Lifetime of a local reference

2019-02-26 Thread Tim Daneliuk
On 2/26/19 3:54 PM, Marko Rauhamaa wrote: > Consider this function: > > def fun(): > f = open("lock") > flock.flock(f, fcntl.LOCK_EX) > do_stuff() > sys.exit(0) > > Question: can a compliant Python implementation close f (and, > consequently, release the file

Re: Lifetime of a local reference

2019-02-26 Thread Chris Angelico
On Wed, Feb 27, 2019 at 9:00 AM Marko Rauhamaa wrote: > Consider this function: > > def fun(): > f = open("lock") > flock.flock(f, fcntl.LOCK_EX) > do_stuff() > sys.exit(0) > > Question: can a compliant Python implementation close f (and, > consequently,

Lifetime of a local reference

2019-02-26 Thread Marko Rauhamaa
Consider this function: def fun(): f = open("lock") flock.flock(f, fcntl.LOCK_EX) do_stuff() sys.exit(0) Question: can a compliant Python implementation close f (and, consequently, release the file lock) before/while do_stuff() is executed? I couldn't find