Re: [Python-ideas] Defer Statement

2017-06-04 Thread Jan Kaliszewski
Hello, 2017-06-04 Nathaniel Smith dixit: > class LazyConstants: > def __getattr__(self, name): > value = compute_value_for(name) > setattr(self, name, value) > return value > > __getattr__ is only called as a fallback, so by setting the computed > value on the object

Re: [Python-ideas] Defer Statement

2017-06-04 Thread Akira Li
Daniel Bershatsky writes: > ... > Proposal > > There is not any mechanism to defer the execution of function in > python. In > order to mimic defer statement one could use either try/except > construction or > use context manager in with statement. > ... Related: "Python equivalent of g

Re: [Python-ideas] Defer Statement

2017-06-04 Thread Nick Coghlan
On 4 June 2017 at 17:37, Nathaniel Smith wrote: > I think in general I'd recommend making the API for accessing these > things be a function call interface, so that it's obvious to the > caller that some expensive computation might be going on. But if > you're stuck with an attribute-lookup based

Re: [Python-ideas] Defer Statement

2017-06-04 Thread Nathaniel Smith
On Sun, Jun 4, 2017 at 12:23 AM, Lucas Wiman wrote: > I agree that the stated use cases are better handled with ExitStack. One > area where `defer` might be useful is in lazy-evaluating global constants. > For example in a genomics library used at my work, one module involves > compiling a large

Re: [Python-ideas] Defer Statement

2017-06-04 Thread Lucas Wiman
I agree that the stated use cases are better handled with ExitStack. One area where `defer` might be useful is in lazy-evaluating global constants. For example in a genomics library used at my work, one module involves compiling a large number of regular expressions, and setting them as global con

Re: [Python-ideas] Defer Statement

2017-06-03 Thread Nick Coghlan
On 3 June 2017 at 22:24, Nick Coghlan wrote: > So while I'm definitely sympathetic to the use case (otherwise > ExitStack wouldn't have a callback() method), "this would be useful" > isn't a sufficient argument in this particular case - what's needed is > a justification that this pattern of resou

Re: [Python-ideas] Defer Statement

2017-06-03 Thread Juancarlo Añez
On Sat, Jun 3, 2017 at 6:59 AM, Daniel Bershatsky wrote: Or with usage defer keyword > > ``` > fin = open(filename) > defer fin.close() > # some stuff > IMHO, a block in which the intention of a `finally: is not well understood, needs refactoring. Some *old* code is like that, but it

Re: [Python-ideas] Defer Statement

2017-06-03 Thread Joshua Morton
Its also worth mentioning that the `defer` statement has come up in other contexts, and is already often used as an identifier already (see *https://mail.python.org/pipermail/python-ideas/2017-February/044682.html *), so ther

Re: [Python-ideas] Defer Statement

2017-06-03 Thread Nick Coghlan
On 3 June 2017 at 20:59, Daniel Bershatsky wrote: > Dear Python Developers, > > We have a potential idea for enhancing Python. You will find a kind of draft > bellow. Thank you for taking the time to write this up! > Best regards, > Daniel Bershatsky > > > Abstract > > > This PEP propos

[Python-ideas] Defer Statement

2017-06-03 Thread Daniel Bershatsky
Dear Python Developers, We have a potential idea for enhancing Python. You will find a kind of draft bellow. Best regards,Daniel Bershatsky  Abstract This PEP proposes the introduction of new syntax to create community standard,readable and clear way to defered function execution in basic b