[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Serhiy Storchaka
08.04.21 19:58, [email protected] пише: > I would like to propose adding literal syntax to allow creation of an empty > set without the need to call the type constructor. I believe the best choice > for such a literal, and one that has been proposed before, is `{,}`. You can now use `{*()}` as a

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-09 Thread Serhiy Storchaka
08.04.21 17:59, anthony.flury via Python-ideas пише: > I was wondering whether a worthwhile extension might be to allow the > `with` statement to have an `except` and  `else` clauses which would > have the same > semantics as wrapping the `with` block with a try - for example the > above would now

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Stéfane Fermigier
I think the best alias for "empty set" would be the Unicode character "Empty set" or U+2205, i.e. "∅". Alas, it's not a valid identifier in Python: >>> ∅ = set() File "", line 1 ∅ = set() ^ SyntaxError: invalid character '∅' (U+2205) It works with the similarly looking "ϕ" or 'GREEK PH

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Chris Angelico
On Fri, Apr 9, 2021 at 6:09 PM Stéfane Fermigier wrote: > > I think the best alias for "empty set" would be the Unicode character "Empty > set" or U+2205, i.e. "∅". > > Alas, it's not a valid identifier in Python: > > >>> ∅ = set() > File "", line 1 > ∅ = set() > ^ > SyntaxError: invali

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Matt del Valle
Oh god, Stephane, you're giving me flashbacks to PEP 3117 ( https://www.python.org/dev/peps/pep-3117/). But not in a good way. Please pretty please let's keep unicode characters out of our code. With regards to the original proposal, for what it's worth, I like it well enough. I think sets are th

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Serhiy Storchaka
09.04.21 12:50, Matt del Valle пише: > I think sets are the only type in the builtins module > without a dedicated literal syntax? Not only. bytearray, frozenset, slice. It is difficult to create some complex objects without using constructor. Not counting range, memoryview and dict views, descrip

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Matt del Valle
Sorry, I really should have had my morning coffee before making that reply. Big-time thinko :) What I meant to say is that the other comparable builtin types (comma-delimited containers of some description) that have literals built into the language (list, tuple, dict) also have a literal that rep

[Python-ideas] Greek alphabet in built-in`string` module

2021-04-09 Thread mitchell . negus . 57
I was wondering if it might be reasonable to consider adding a set of Greek letters to the constants in the `string` module. In my mind, the format would follow the existing convention—constants for both `greek_lowercase` and `greek_uppercase`, as well as a combined constant `greek_letters`. Ju

[Python-ideas] Re: Greek alphabet in built-in`string` module

2021-04-09 Thread David Mertz
Would it include digamma, san, koppa, or sampi... Or strictly Koine letters? To a lesser extent than Greek, Hebrew letters are also used commonly in math. What about the double struck capitals like ℤ, ℚ, and ℕ? It kinda feels like a very simple third party module couple give many such names for

[Python-ideas] Re: Greek alphabet in built-in`string` module

2021-04-09 Thread Paul Bryan
This sounds more like a Unicode thing than a generic string thing. And, in Uncode, Greek characters are included in multiple groupings. Searching for "Theta" to see what we get: Greek and Coptic: U+0398 GREEK CAPITAL LETTER THETA U+03B8 GREEK SMALL LETTER THETA U+03D1 GREEK THETA SYMBOL U+03F4 GRE

[Python-ideas] Re: Greek alphabet in built-in`string` module

2021-04-09 Thread Chris Angelico
On Sat, Apr 10, 2021 at 12:15 AM Paul Bryan wrote: > > This sounds more like a Unicode thing than a generic string thing. And, in > Uncode, Greek characters are included in multiple groupings. Searching for > "Theta" to see what we get: > > Greek and Coptic: > U+0398 GREEK CAPITAL LETTER THETA >

[Python-ideas] Re: Greek alphabet in built-in`string` module

2021-04-09 Thread Paul Bryan
I agree. It would be great to get something more than what the simplistic `unicodedata.category(...)` returns; for example, what Unicode group a character falls in. On Sat, 2021-04-10 at 00:29 +1000, Chris Angelico wrote: > On Sat, Apr 10, 2021 at 12:15 AM Paul Bryan wrote: > > > > This sounds m

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread micro codery
> > > You can now use `{*()}` as a syntax for empty set. > > I saw that in the ast module and think it's clever, mainly in a good way. I don't think it is the same as having dedicated syntax for the empty set partly because I think it needs to be taught. I don't think a new pythonista would turn to

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Ricky Teachey
On Fri, Apr 9, 2021 at 3:20 AM Serhiy Storchaka wrote: > 08.04.21 19:58, [email protected] пише: > > I would like to propose adding literal syntax to allow creation of an > empty set without the need to call the type constructor. I believe the best > choice for such a literal, and one that has be

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Christopher Barker
On Fri, Apr 9, 2021 at 6:06 AM Matt del Valle wrote: > > What I meant to say is that the other comparable builtin types > (comma-delimited containers of some description) that have literals built > into the language (list, tuple, dict) also have a literal that represents > an empty version of the

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Chris Angelico
On Sat, Apr 10, 2021 at 2:44 AM Ricky Teachey wrote: > > On Fri, Apr 9, 2021 at 3:20 AM Serhiy Storchaka wrote: >> >> 08.04.21 19:58, [email protected] пише: >> > I would like to propose adding literal syntax to allow creation of an >> > empty set without the need to call the type constructor. I

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread David Mertz
I don't do twitter, so hadn't seen Raymond's comment. But I agree that `{*()}` is too-clever-by-half. Moreover, it's the same character count as `set()`, so it doesn't even save anything. Using five characters to create an empty `set()` really isn't that many. I do that all the time. Proposals

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Ricky Teachey
On Fri, Apr 9, 2021 at 1:30 PM David Mertz wrote: > I don't do twitter, so hadn't seen Raymond's comment. But I agree that > `{*()}` is too-clever-by-half. Moreover, it's the same character count as > `set()`, so it doesn't even save anything. > > Using five characters to create an empty `set()

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-09 Thread Guido van Rossum
But if there are two proposals with conflicting semantics for the same syntax that kills both ideas, doesn’t it? Because apparently it’s not clear what the syntax should mean. On Fri, Apr 9, 2021 at 00:28 Serhiy Storchaka wrote: > 08.04.21 17:59, anthony.flury via Python-ideas пише: > > I was wo

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-09 Thread anthony.flury via Python-ideas
On 09/04/2021 19:02, Guido van Rossum wrote: But if there are two proposals with conflicting semantics for the same syntax that kills both ideas, doesn’t it? Because apparently it’s not clear what the syntax should mean. Surely it depends (if we adopt a proposal) how we document it. You could

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-09 Thread Ethan Furman
On 4/9/21 11:33 AM, anthony.flury via Python-ideas wrote: On 09/04/2021 19:02, Guido van Rossum wrote: But if there are two proposals with conflicting semantics for the same syntax that kills both ideas, doesn’t it? Because apparently it’s not clear what the syntax should mean. Surely it dep

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Peter Ludemann
David Mertz wrote: > The pattern of "Create an empty collection, then add stuff in a loop" is > quite common, ... Or you can use comprehensions, in which case there's no need for creating an empty collection. s = {f(x) for x in some_list} vs s = set() for x in some_list: s.add(f(x)) __

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread David Mertz
On Fri, Apr 9, 2021, 3:23 PM Peter Ludemann wrote: > David Mertz wrote: > > The pattern of "Create an empty collection, then add stuff in a loop" is > quite common, ... > > Or you can use comprehensions, in which case there's no need for creating > an empty collection. > > s = {f(x) for x in some

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Jonathan Fine
In August 2020, in the context of PEP 472 I suggested >>> {-} for the empty set literal. At present the closest we can do for an empty set literal is >>> {0} - {0} set() The context for this is whether PEP 472 should make >>> something[] a syntax error. If we do then, what about th

[Python-ideas] Re: Python Idea - extension of 'with'

2021-04-09 Thread Mike Miller
On 2021-04-08 11:25, Chris Angelico wrote: On Fri, Apr 9, 2021 at 2:24 AM Paul Bryan wrote: Q. Safe to assume this would catch exceptions from both the call to `open` as well as the call to `open.__enter__`? No, not safe to assume. It's equally reasonable to define it as guarding only the

[Python-ideas] Re: Adding syntax for the empty set

2021-04-09 Thread Skip Montanaro
> > $ def unpack_set(): > > return {*()} > > > $ dis.dis(unpack_set) > 2 0 BUILD_SET0 > 2 LOAD_CONST 1 (()) > 4 SET_UPDATE 1 > 6 RETURN_VALUE > Seems like the peephole optimizer could be trained t