<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Oct 24, 2018 at 4:41 PM Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, Oct 24, 2018 at 09:18:14AM -0400, Calvin Spealman wrote:<br>
> I'd like to suggest what I think would be a simple addition to `def` and<br>
> `class` blocks. I don't know if calling those "Assignment Blocks" is<br>
> accurate, but I just mean to refer to block syntaxes that assign to a name.<br>
> Anyway, I propose a combined return-def structure, and optionally also<br>
> allowing a return-class version. Omitting the name would be allowable, as<br>
> well.<br>
> <br>
> This would only apply to a `def` or `class` statement made as the last part<br>
> of the function body, of course.<br>
> <br>
> def ignore_exc(exc_type):<br>
>     return def (func):<br>
>         @wraps(func)<br>
>         return def (*args, **kwargs):<br>
>             try:<br>
>                 return func(*args, **kwargs)<br>
>             except exc_type:<br>
>                 pass<br>
<br>
Your example is too complex for me this early in the morning -- I can't <br>
tell what it actually *does*, as it is obscured by what looks like a <br>
bunch of irrelevent code.<br>
<br>
I *think* you are proposing the following syntax. Am I right?<br>
<br>
<br>
return def (func):<br>
    # body of func<br>
<br>
which is equivalent to:<br>
<br>
def func:<br>
    # body of func<br>
return func<br>
<br>
And similar for classes:<br>
<br>
return class (K):<br>
    # body of K<br>
<br>
being equivalent to:<br>
<br>
class K:<br>
    # body of K<br>
return K<br>
<br>
<br>
Is it intentional that your example function takes no arguments? If the <br>
function did, where would the parameter list go in your syntax?<br>
<br>
Aside from saving one line, what is the purpose of this?<br>
</blockquote><div><br></div><div>The point is not saving a line or typing, but saving a thought. Expressing the intent of the factory function more clearly.</div><div><br></div><div>Decorators don't do more than "saving one line", either.</div><div><br></div><div>But the biggest reason I'd like something like this is that it solves a *specific* version of the multi-line anonymous function that comes up over and over and over again, and maybe by chipping away at those use-cases we can stop seeing *that* debate over and over and over again. :-)</div><div><br></div><div>So, no, it doesn't save a lot of typing, but I'm never interested in that. I don't spend a lot of time typing code, I spend it reading code, and something like this would certainly help there, imho.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
-- <br>
Steve<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div></div>