[Python-ideas] Re: Enum: determining if a value is valid

2021-03-15 Thread Guido van Rossum
You have a good point (and as static typing proponent I should have thought of that). Maybe there is not actually a use case for passing an arbitrary default? Then maybe overloading __contains__ (‘in’) might be better? The ergonomics of that seem better for the dominant use case (“is this a valid

[Python-ideas] Re: Enum: determining if a value is valid

2021-03-15 Thread Matt Wozniski
I find the idea of having the constructor potentially return something other than an instance of the class to be very... off-putting. Maybe it's the best option, but my first impression of it isn't favorable, and I can't think of any similar case that exists in the stdlib today off the top of my

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-15 Thread Eric V. Smith
On 3/15/2021 7:45 PM, Guido van Rossum wrote: Good proposal! I have a few questions. Thanks for the feedback. On Mon, Mar 15, 2021 at 2:22 PM Eric V. Smith > wrote: [I'm sort of loose with the terms field, parameter, and argument here. Forgive me: I

[Python-ideas] Re: dataclasses keyword-only fields, take 2

2021-03-15 Thread Guido van Rossum
Good proposal! I have a few questions. On Mon, Mar 15, 2021 at 2:22 PM Eric V. Smith wrote: > [I'm sort of loose with the terms field, parameter, and argument here. > Forgive me: I think it's still understandable. Also I'm not specifying > types here, I'm using Any everywhere. Use your

[Python-ideas] dataclasses keyword-only fields, take 2

2021-03-15 Thread Eric V. Smith
[I'm sort of loose with the terms field, parameter, and argument here. Forgive me: I think it's still understandable. Also I'm not specifying types here, I'm using Any everywhere. Use your imagination and substitute real types if it helps you.] Here's version 2 of my proposal: There have

[Python-ideas] Re: Enum: determining if a value is valid

2021-03-15 Thread Guido van Rossum
+1 On Mon, Mar 15, 2021 at 12:48 PM Ethan Furman wrote: > On 3/15/21 11:27 AM, Guido van Rossum wrote: > > On Mon, Mar 15, 2021 at 10:53 AM Ethan Furman wrote: > > >> Part of the reason is that there are really two ways to identify an > >> enum -- by name, and by value -- which should

[Python-ideas] Re: Enum: determining if a value is valid

2021-03-15 Thread Ethan Furman
On 3/15/21 11:27 AM, Guido van Rossum wrote: On Mon, Mar 15, 2021 at 10:53 AM Ethan Furman wrote: Part of the reason is that there are really two ways to identify an enum -- by name, and by value -- which should `__contains__` work with? The two sets don't overlap, so we could allow both.

[Python-ideas] Re: Enum: determining if a value is valid

2021-03-15 Thread Ricky Teachey
On Mon, Mar 15, 2021 at 2:28 PM Guido van Rossum wrote: > > ... >> >> I think I like your constructor change idea, with a small twist: >> >> Color(value=, name=, default=) >> >> This would make it possible to search for an enum by value or by name, >> and also specify a default return value

[Python-ideas] Re: Enum: determining if a value is valid

2021-03-15 Thread Guido van Rossum
On Mon, Mar 15, 2021 at 10:53 AM Ethan Furman wrote: > On 3/12/21 5:28 PM, Guido van Rossum wrote: > > On Fri, Mar 12, 2021 at 1:52 PM Ethan Furman wrote: > > >> A question that comes up quite a bit on Stackoverflow is how to test > >> to see if a value will result in an Enum member, preferably

[Python-ideas] Re: Enum: determining if a value is valid

2021-03-15 Thread Ethan Furman
On 3/12/21 5:28 PM, Guido van Rossum wrote: On Fri, Mar 12, 2021 at 1:52 PM Ethan Furman wrote: A question that comes up quite a bit on Stackoverflow is how to test to see if a value will result in an Enum member, preferably without having to go through the whole try/except machinery. A

[Python-ideas] Re: Add an export keyword to better manage __all__

2021-03-15 Thread Rob Cliffe via Python-ideas
On 15/03/2021 05:54, Ethan Furman wrote: On 3/14/21 12:42 PM, Stestagg wrote: The value of being able to (in specific cases) reach into third-party code, and customize it to work for your specific situation should not be disregarded. I completely agree with this.  One of the hallmarks of

[Python-ideas] Re: allow initial comma

2021-03-15 Thread Todd
On Mon, Mar 15, 2021, 06:15 Roland Puntaier via Python-ideas < python-ideas@python.org> wrote: > On Fri 21Mar12 14:27, Paul Bryan wrote: > >It seems your proposal is intended to address an aesthetic concern. Is > >there a case where using a leading comma would make something > >actually easier or