[Python-ideas] Return for assignment blocks
Rhodri James
rhodri at kynesim.co.uk
Wed Oct 24 10:50:54 EDT 2018
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
More information about the Python-ideas
mailing list