On 24/10/2018 15:04, Calvin Spealman wrote:
My idea is not "assignment blocks" those already exist. `def` and `class`
blocks are both syntaxes that assign to some name. I'm just using the term
to refer to them as a group.

The proposal is just being able to return them. These two examples become
equivalent:

def ignore_exc(exc_type):
     return def (func):
         @wraps(func)
         return def (*args, **kwargs):
             try:
                 return func(*args, **kwargs)
             except exc_type:
                 pass

def ignore_exc(exc_type):
     def decorator(func):
         @wraps(func)
         def wrapped_func(*args, **kwargs):
             try:
                 return func(*args, **kwargs)
             except exc_type:
                 pass
         return wrapped_func
     return decorator

Essentially this is a limited multi-line lambda. Either people are going to be surprised that you can only use it in a return statement or you have to open the whole can of worms about multi-line lambdas. Good luck on the latter.

--
Rhodri James *-* Kynesim Ltd
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to