[Python-ideas] Re: Unpacking in tuple/list/set/dict comprehensions

2021-10-17 Thread Guido van Rossum
On Sun, Oct 17, 2021 at 4:38 PM Steven D'Aprano wrote: > Right-o, the old "heterogeneous tuples versus homogeneous lists" > distinction, I remember that from the old 1.5 days. I haven't heard it > mentioned for a long time! > You must not have looked at type annotations then. :-) Type

[Python-ideas] Re: Unpacking in tuple/list/set/dict comprehensions

2021-10-17 Thread Steven D'Aprano
We don't have tuple comprehensions, and this proposal isn't to add them, so this post is edging into off-topic for the thread so feel free to skip it. On Sat, Oct 16, 2021 at 03:18:20PM -0400, David Mertz, Ph.D. wrote: > Rather, I'm concerned with readability and programmer expectations.

[Python-ideas] Re: Except * formatting

2021-10-17 Thread Steven D'Aprano
On Sun, Oct 17, 2021 at 02:48:48PM +0100, Rob Cliffe via Python-ideas wrote: > I'm sending this to python-list because my emails to python-dev keep > getting bounced back (after a few days delay).  I've no idea why. If you are getting a bounce message, as opposed to the email just disappearing

[Python-ideas] Re: Unpacking in tuple/list/set/dict comprehensions

2021-10-17 Thread Eric V. Smith
> On Oct 17, 2021, at 3:40 AM, Serhiy Storchaka wrote: > > 16.10.21 17:07, Erik Demaine пише: >> (*it for it in its) # tuple with the concatenation of iterables in 'its' > > As others already have said, it should evaluate to a generator, not to a > tuple. > > But other question is occurred

[Python-ideas] Re: Unpacking in tuple/list/set/dict comprehensions

2021-10-17 Thread Serhiy Storchaka
17.10.21 16:08, Eric V. Smith пише: > Serhiy: could you explain the difference? The difference between `for x in it: yield x` and `yield from it` is than in the latter case any values passed in with send() and any exceptions passed in with throw() are passed to the underlying iterator if it has

[Python-ideas] Except * formatting

2021-10-17 Thread Rob Cliffe via Python-ideas
I'm sending this to python-list because my emails to python-dev keep getting bounced back (after a few days delay).  I've no idea why. Instead of `except group ...`, what about `except for ...`? No new keywords. Reads naturally in English. Hints that there is more than one kind of exception

[Python-ideas] Re: Structure Pattern for annotation

2021-10-17 Thread Joren Hammudoglu
I guess you could work around this by exploiting the slicing operator: GenericClass[:(A, B)] It makes sense to use the : in the context of typing, but I can see how this syntax can be confusing. The least confusing implementation I could think of is to limit the use of GenericClass[:_] to

[Python-ideas] Re: Unpacking in tuple/list/set/dict comprehensions

2021-10-17 Thread Chris Angelico
On Sun, Oct 17, 2021 at 8:26 PM Steven D'Aprano wrote: > (I think the difference has to do with sending values into the > generator, throwing and catching exceptions, but I can't think of a > simple example where it would make a difference.) Yeah mainly. And genexps don't usually do that. So it

[Python-ideas] Re: Unpacking in tuple/list/set/dict comprehensions

2021-10-17 Thread Steven D'Aprano
We can already easily simulate your first alternative in a generator comprehension: (x for it in its for x in it) # equivalent to def gen(its): for it in its: for x in it: yield x so anyone who wants that behaviour can easily get it. So

[Python-ideas] Re: Accessing target name at runtime

2021-10-17 Thread Serhiy Storchaka
08.10.21 22:23, Jeremiah Paige пише: Point = namedtuple(<<<, 'x, y, z') Point > > > UUIDType = NewType(<<<, str) UUIDType > __main__.UUIDType In many cases similar to namedtuple and NewType this is not enough. You need to pass to the constructor not only name, but module

[Python-ideas] Re: Unpacking in tuple/list/set/dict comprehensions

2021-10-17 Thread Serhiy Storchaka
16.10.21 17:07, Erik Demaine пише: > (*it for it in its)  # tuple with the concatenation of iterables in 'its' As others already have said, it should evaluate to a generator, not to a tuple. But other question is occurred now. Should it be equivalent to def gen(its): for it in its: