[Python-ideas] Return for assignment blocks

Calvin Spealman cspealma at redhat.com
Wed Oct 24 09:18:14 EDT 2018


I'd like to suggest what I think would be a simple addition to `def` and
`class` blocks. I don't know if calling those "Assignment Blocks" is
accurate, but I just mean to refer to block syntaxes that assign to a name.
Anyway, I propose a combined return-def structure, and optionally also
allowing a return-class version. Omitting the name would be allowable, as
well.

This would only apply to a `def` or `class` statement made as the last part
of the function body, of course.

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

Thanks for considering and for any comments, thoughts, or feedback on the
idea!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181024/950fd1d9/attachment.html>


More information about the Python-ideas mailing list