[Python-Dev] format, int, and IntEnum (original) (raw)
Ethan Furman ethan at stoneleaf.us
Wed Aug 21 09:06:13 CEST 2013
- Previous message: [Python-Dev] format, int, and IntEnum
- Next message: [Python-Dev] PEP 450 adding statistics module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 08/20/2013 11:15 PM, Ethan Furman wrote:
On 08/14/2013 09:27 PM, Nick Coghlan wrote:
For enums, I believe they should be formatted like their base types (so !s and !r will show the enum name, anything without coercion will show the value) . I agree. While one of the big reasons for an Enum type was the pretty str and repr, I don't see format in that area. How often will one type in
"{}".format(somevar)
to find out what type of object one has? Myself, I would just typesomevar
.
So, these are some of the ways we have to display an object:
str() calls obj.str() repr() calls obj.repr()
"%s" calls obj.str() "%r" calls obj.repr() "%d" calls... not sure, but we see the int value
"{}".format() should (IMO) also display the value of the object
Using int as the case study, its presentation types are ['b', 'd', 'n', 'o', 'x', 'X']. Notice there is no 's' nor 'r' in there, as int expects to display a number, not arbitrary text.
So, for mixed-type Enumerations, I think any format calls should simply be forwarded to the mixed-in type (unless, of course, a custom format was specified in the new Enumeration).
--
Ethan
- Previous message: [Python-Dev] format, int, and IntEnum
- Next message: [Python-Dev] PEP 450 adding statistics module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]