<div dir="ltr"><div>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.</div><div><br></div><div>The proposal is just being able to return them. These two examples become equivalent:</div><div><br></div><div>
<div>def ignore_exc(exc_type):</div><div> return def (func):</div><div> @wraps(func)<br></div><div> return def (*args, **kwargs):</div><div> try:</div><div>
return func(*args, **kwargs)</div><div>
except exc_type:</div><div>
pass</div>
</div><div><br></div><div>
<div>def ignore_exc(exc_type):</div><div> def decorator(func):</div><div> @wraps(func)<br></div><div> def wrapped_func(*args, **kwargs):</div><div> try:</div><div>
return func(*args, **kwargs)</div><div>
except exc_type:</div><div>
pass</div><div> return wrapped_func</div><div> return decorator<br></div>
</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Oct 24, 2018 at 9:51 AM Benedikt Werner <<a href="mailto:1benediktwerner@gmail.com">1benediktwerner@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<p>Would you mind providing a bit more details about your proposal?</p>
<p> What exactly are those "Assignment Blocks" supposed to do?</p>
<p>If I understand your proposal correctly you want this:</p>
<p>def my_func():<br>
return def():<br>
print("abc")</p>
<p>to be the same as this:</p>
<p>def my_func():<br>
def inner_func():<br>
print("abc")<br>
return inner_func</p>
<p>But this is only my assumption as your proposal doesn't give very
much details.<br>
Maybe you should provide a few simple examples and explain what
they are supposed to do or what they should be equivalent to.</p>
<p>Your example is quite complex and to me it's not clear at all
what it is supposed to mean.<br>
</p>
<p>Also and probably most importantly what is the reason you want
this? Are there any good usecases where this would help?</p>
<p>If my assumption above is correct this just looks like a bit of
syntactic sugar that IMO isn't really neccessary. It doesn't
really improve readability or save many characters. The existing
way to do this is totally fine.</p>
<p>Benedikt<br>
</p>
<br>
<div class="m_3707962311461512867moz-cite-prefix">Am 24.10.2018 um 15:18 schrieb Calvin
Spealman:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>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.<br>
</div>
<div><br>
</div>
<div>This would only apply to a `def` or `class` statement made
as the last part of the function body, of course.</div>
<div><br>
</div>
<div>def ignore_exc(exc_type):</div>
<div> return def (func):</div>
<div> @wraps(func)<br>
</div>
<div> return def (*args, **kwargs):</div>
<div> try:</div>
<div>
return func(*args, **kwargs)</div>
<div>
except exc_type:</div>
<div>
pass</div>
<div><br>
</div>
<div>Thanks for considering and for any comments, thoughts, or
feedback on the idea!<br>
</div>
</div>
<br>
<fieldset class="m_3707962311461512867mimeAttachmentHeader"></fieldset>
<br>
<pre>_______________________________________________
Python-ideas mailing list
<a class="m_3707962311461512867moz-txt-link-abbreviated" href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a>
<a class="m_3707962311461512867moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a>
Code of Conduct: <a class="m_3707962311461512867moz-txt-link-freetext" href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a>
</pre>
</blockquote>
<br>
</div>
_______________________________________________<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>