Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Greg Ewing
Calvin Spealman wrote: You know what, I /can't/ think of other good examples than slightly improved decorators. So, maybe its not that great an idea if it can't be applied to at least a few more use cases. The class version might be useful for things like namedtuple that dynamically create

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Steven D'Aprano
On Thu, Oct 25, 2018 at 08:44:44AM -0400, Calvin Spealman wrote: > On Wed, Oct 24, 2018 at 4:41 PM Steven D'Aprano wrote: [...] > > I *think* you are proposing the following syntax. Am I right? > > > > > > return def (func): > > # body of func > > > > which is equivalent to: > > > > def func:

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Guido van Rossum
On Thu, Oct 25, 2018 at 7:41 AM Calvin Spealman wrote: > > On Thu, Oct 25, 2018 at 9:28 AM Anders Hovmöller > wrote: > >> [Calvin] >> > The point is not saving a line or typing, but saving a thought. >> Expressing the intent of the factory function more clearly. >> > [...] > You know what, I

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Calvin Spealman
On Thu, Oct 25, 2018 at 9:28 AM Anders Hovmöller wrote: > > > The point is not saving a line or typing, but saving a thought. > Expressing the intent of the factory function more clearly. > > Could you give some other usage examples? > > To me it seems like a nicer and less confusing way to

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Anders Hovmöller
> The point is not saving a line or typing, but saving a thought. Expressing > the intent of the factory function more clearly. Could you give some other usage examples? To me it seems like a nicer and less confusing way to create decorators is warranted but could then be more specialized

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Calvin Spealman
On Wed, Oct 24, 2018 at 4:41 PM Steven D'Aprano wrote: > On Wed, Oct 24, 2018 at 09:18:14AM -0400, Calvin Spealman wrote: > > 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

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Rhodri James
On 25/10/2018 02:15, Virendra Tripathi wrote: In addition to what GVR wrote, a generator function would have to have its own syntax - backward compatibility would be another issue. No it wouldn't. This is about returning the function/generator/class itself, not its results. I still don't

Re: [Python-ideas] Return for assignment blocks

2018-10-24 Thread Virendra Tripathi
In addition to what GVR wrote, a generator function would have to have its own syntax - backward compatibility would be another issue. Virendra Tripathi Santa Clara, CA 415-910-4955 trip...@gmail.com On Wed, Oct 24, 2018 at 2:31 PM Greg Ewing wrote: > Calvin Spealman wrote: > > > def

Re: [Python-ideas] Return for assignment blocks

2018-10-24 Thread Steven D'Aprano
On Wed, Oct 24, 2018 at 09:18:14AM -0400, Calvin Spealman wrote: > 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,

Re: [Python-ideas] Return for assignment blocks

2018-10-24 Thread Rhodri James
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

Re: [Python-ideas] Return for assignment blocks

2018-10-24 Thread Calvin Spealman
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):

Re: [Python-ideas] Return for assignment blocks

2018-10-24 Thread Benedikt Werner
Would you mind providing a bit more details about your proposal? What exactly are those "Assignment Blocks" supposed to do? If I understand your proposal correctly you want this: def my_func():     return def():     print("abc") to be the same as this: def my_func():     def

[Python-ideas] Return for assignment blocks

2018-10-24 Thread Calvin Spealman
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