[Python-Dev] Re: Enum and the Standard Library

2020-09-22 Thread Serhiy Storchaka
22.09.20 16:57, Ethan Furman пише: > On 9/22/20 12:11 AM, Serhiy Storchaka wrote: >> The only exception is StrEnum -- overriding __str__ of str >> subclass may be not safe. Some code will call str() implicitly, other >> will read the string content of the object directly, and they will be >> differ

[Python-Dev] Re: Enum and the Standard Library

2020-09-22 Thread Ethan Furman
On 9/22/20 12:11 AM, Serhiy Storchaka wrote: The only exception is StrEnum -- overriding __str__ of str subclass may be not safe. Some code will call str() implicitly, other will read the string content of the object directly, and they will be different. Following up on that: >>> import e

[Python-Dev] Re: Enum and the Standard Library

2020-09-22 Thread Serhiy Storchaka
19.09.20 00:44, Ethan Furman пише: > I'm looking for arguments relating to: > > - should _convert_ make the default __repr__ be module_name.member_name? In most cases enums with _convert_ are used to replace old module globals. They are accessible as module_name.member_name and always used as mod

[Python-Dev] Re: Enum and the Standard Library

2020-09-21 Thread Luciano Ramalho
On Fri, Sep 18, 2020 at 10:42 PM Guido van Rossum wrote: > At the same time it's as old as Python -- for most builtins other than > strings, repr() and str() are the same, and modeled after repr(). > Historically, I only introduced the difference between str() and repr() > because of strings --

[Python-Dev] Re: Enum and the Standard Library

2020-09-21 Thread Ethan Furman
On 9/19/20 2:08 PM, Guido van Rossum wrote: I'm just trying to present an argument that if the str() of an enum was its name and the repr() was its "full name" (at least including the class) that would be pretty sweet. Well, we're still early enough in the 3.10 cycle we can make that change

[Python-Dev] Re: Enum and the Standard Library

2020-09-19 Thread Guido van Rossum
That would be more palatable if it wasn't so common to use manually assigned numerical values (as most of the examples in the enum module docs do) or the default auto(). I'm just trying to present an argument that if the str() of an enum was its name and the repr() was its "full name" (at least in

[Python-Dev] Re: Enum and the Standard Library

2020-09-19 Thread Chris Angelico
On Sat, Sep 19, 2020 at 11:44 AM Guido van Rossum wrote: > Another brainstorm (or brainfart): maybe repr() should show the module/class > and the name, and str() should only show the name. We'd then get > ``` > >>> # Mock-up! > >>> print(str(re.i)) > IGNORE > >>> print(repr(re.i)) > re.IGNORE > >

[Python-Dev] Re: Enum and the Standard Library

2020-09-19 Thread Ethan Furman
On 9/19/20 11:32 AM, Guido van Rossum wrote: > On Sat, Sep 19, 2020 at 1:29 AM Ethan Furman wrote: >> On 9/18/20 6:41 PM, Guido van Rossum wrote: >>> Another brainstorm (or brainfart): maybe repr() should show the >>> module/class and the name, and str() should only show the name. We'd >>> then g

[Python-Dev] Re: Enum and the Standard Library

2020-09-19 Thread Guido van Rossum
On Sat, Sep 19, 2020 at 1:29 AM Ethan Furman wrote: > On 9/18/20 6:41 PM, Guido van Rossum wrote: > [...] > > Another brainstorm (or brainfart): maybe repr() should show the > > module/class and the name, and str() should only show the name. We'd > > then get > > ``` > > >>> # Mock-up! > >

[Python-Dev] Re: Enum and the Standard Library

2020-09-19 Thread Antoine Pitrou
On Fri, 18 Sep 2020 18:14:35 -0700 Ethan Furman wrote: > > So at this point, I think the choices are: > > Standard Enum >__repr__ __str__ >RegexFlag.IGNORECASE > > and > > Modified Converted Constant >__repr__ __str__ > re.IGNORECASE

[Python-Dev] Re: Enum and the Standard Library

2020-09-19 Thread Stephen J. Turnbull
Ethan Furman writes: > I counted roughly 25 Enums in the stdlib at this point, and only two of > them have modified reprs or strs; and one of those is an internal class. > It's worth noting that two others are buggy -- one is being fancy with > values and didn't get the custom __new__ cor

[Python-Dev] Re: Enum and the Standard Library

2020-09-19 Thread Ethan Furman
On 9/18/20 6:41 PM, Guido van Rossum wrote: > On Fri, Sep 18, 2020 at 6:19 PM Ethan Furman wrote: >> So at this point, I think the choices are: >> >> Standard Enum >> __repr__ __str__ >>RegexFlag.IGNORECASE >> >> and >> >> Modified Converted Constant >> _

[Python-Dev] Re: Enum and the Standard Library

2020-09-18 Thread Guido van Rossum
On Fri, Sep 18, 2020 at 6:19 PM Ethan Furman wrote: > On 9/18/20 3:12 PM, Guido van Rossum wrote: > > On 9/18/20 2:44 PM, Ethan Furman wrote: > > >> I'm looking for arguments relating to: > >> > >> - should _convert_ make the default __repr__ be > >> module_name.member_name? > > > > I ac

[Python-Dev] Re: Enum and the Standard Library

2020-09-18 Thread Ethan Furman
On 9/18/20 3:12 PM, Guido van Rossum wrote: > On 9/18/20 2:44 PM, Ethan Furman wrote: >> I'm looking for arguments relating to: >> >> - should _convert_ make the default __repr__ be >> module_name.member_name? > > I actually like the status quo for regular enums, when repr() shows > the type, n

[Python-Dev] Re: Enum and the Standard Library

2020-09-18 Thread Guido van Rossum
Okay, let me take a shot at this. I actually like the status quo for regular enums, when repr() shows the type, name and value, and str() shows "classname.flagname", so I'd stick to that for converted flags. Even though this violates the rule of thumb that repr() should look like a valid expressio