Re: [Python-ideas] Proposal: Allowing any variable to be used in a 'with... as...' expression

2019-05-19 Thread Eric V. Smith
On 5/18/2019 8:13 PM, Yonatan Zunger wrote: ... For example, this is a good pattern: with functionReturningFile(...) as input:    doSomething(input) There are many cases where an Optional[file] makes sense as a parameter, as well; for example, an optional debug output stream, or an input sou

Re: [Python-ideas] Proposal: Allowing any variable to be used in a 'with... as...' expression

2019-05-19 Thread Terry Reedy
On 5/19/2019 3:00 PM, Chris Angelico wrote: On Mon, May 20, 2019 at 4:46 AM Terry Reedy wrote: On 5/18/2019 10:01 PM, Chris Angelico wrote: 2) Redefine the 'with' block or create a new syntactic form such that the variable actually creates a subscope. That way, at the end of the block, the n

Re: [Python-ideas] Proposal: Allowing any variable to be used in a 'with... as...' expression

2019-05-19 Thread Chris Angelico
On Mon, May 20, 2019 at 4:46 AM Terry Reedy wrote: > > On 5/18/2019 10:01 PM, Chris Angelico wrote: > > > 2) Redefine the 'with' block or create a new syntactic form such that > > the variable actually creates a subscope. That way, at the end of the > > block, the name would revert to its former m

Re: [Python-ideas] Proposal: Allowing any variable to be used in a 'with... as...' expression

2019-05-19 Thread Terry Reedy
On 5/18/2019 10:01 PM, Chris Angelico wrote: 2) Redefine the 'with' block or create a new syntactic form such that the variable actually creates a subscope. That way, at the end of the block, the name would revert to its former meaning. x = 1 with local 2 as x: print(x) # 2 print(x) # 1

Re: [Python-ideas] Proposal: Allowing any variable to be used in a 'with... as...' expression

2019-05-19 Thread Terry Reedy
On 5/18/2019 10:44 PM, Yonatan Zunger wrote: Terry, let me make sure I'm understanding your responses. (1) Only certain things should be CM's, and those things should be explicitly denoted as such. Thinking about the first one, the purpose of the context manager protocol is to allow cleanup