Re: Enum + new in 3.11

2023-06-16 Thread Thomas Passin via Python-list
On 6/16/2023 7:37 PM, dn via Python-list wrote: On 16/06/2023 23.47, Thomas Passin via Python-list wrote: On 6/16/2023 1:40 AM, dn via Python-list wrote: Have you figured-out a use for the @enum.member and @enum.nonmember decorators (new in Python 3.11)? mypy is having trouble with 3.11 enu

Re: Enum + new in 3.11

2023-06-16 Thread dn via Python-list
On 16/06/2023 23.47, Thomas Passin via Python-list wrote: On 6/16/2023 1:40 AM, dn via Python-list wrote: Have you figured-out a use for the @enum.member and @enum.nonmember decorators (new in Python 3.11)? mypy is having trouble with 3.11 enums: "There are 83 open Enum mypy issues at the t

Re: Enum + new in 3.11

2023-06-16 Thread Thomas Passin via Python-list
On 6/16/2023 1:40 AM, dn via Python-list wrote: Have you figured-out a use for the @enum.member and @enum.nonmember decorators (new in Python 3.11)? "What's New" says: Added the member() and nonmember() decorators, to ensure the decorated object is/is not converted to an enum member. The PS

Re: Enum with nested classes or with types as members

2018-09-12 Thread Ben Finney
Ethan Furman writes: > I'm asking because in doing some work on Enum it became apparent to me > that having nested classes was not a smooth, satisfying experience, > and I'm considering treating them the same way as methods (they will > no longer be converted into members). For reference (and to

Re: enum

2017-10-31 Thread Cousin Stanley
ast wrote: > https://docs.python.org/3.5/library/enum.html#planet > > Documentation says that the value of the enum > members will be passed to this method. > > But in that case __init__ waits for two arguments, mass > and radius, while enum member's value is a tuple. > > It seems that there is

Re: Enum with only a single member

2017-01-10 Thread Peter Otten
Steven D'Aprano wrote: > Is it silly to create an enumeration with only a single member? That is, a > singleton enum? > > from enum import Enum > > class Unique(Enum): > FOO = auto() > > > The reason I ask is that I have two functions that take an enum argument. > The first takes one of th

Re: Enum with only a single member

2017-01-10 Thread jmp
On 01/10/2017 05:43 AM, Steven D'Aprano wrote: Is it silly to create an enumeration with only a single member? That is, a singleton enum? Don't think so, for the same reason that lists with one element make sense. def ham(arg): if isinstance(arg, MarxBros) or arg is Unique.FOO:

Re: Enum with only a single member

2017-01-10 Thread Ethan Furman
On 01/10/2017 12:37 AM, Chris Angelico wrote: On Tue, Jan 10, 2017 at 7:33 PM, Paul Rubin wrote: That is, a singleton enum? Why stop there? You can make empty ones too. (Zerotons?) Sure you *can*, but I can't think of any time they'd be useful. Can you give an example? Sure. Any time

Re: Enum with only a single member

2017-01-10 Thread Chris Angelico
On Tue, Jan 10, 2017 at 7:33 PM, Paul Rubin wrote: >> That is, a singleton enum? > > Why stop there? You can make empty ones too. (Zerotons?) Sure you *can*, but I can't think of any time they'd be useful. Can you give an example? ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Enum with only a single member

2017-01-10 Thread Paul Rubin
Steven D'Aprano writes: > Is it silly to create an enumeration with only a single member? No. > That is, a singleton enum? Why stop there? You can make empty ones too. (Zerotons?) > The reason I ask is that I have two functions that take an enum > argument. Sounds like a good reason. >

Re: Enum with only a single member

2017-01-09 Thread Jussi Piitulainen
Steven D'Aprano writes: > Is it silly to create an enumeration with only a single member? That > is, a singleton enum? > > from enum import Enum > > class Unique(Enum): > FOO = auto() > > > The reason I ask is that I have two functions that take an enum > argument. The first takes one of three

Re: Enum with only a single member

2017-01-09 Thread Ethan Furman
On 01/09/2017 08:43 PM, Steven D'Aprano wrote: Is it silly to create an enumeration with only a single member? That is, a singleton enum? from enum import Enum class Unique(Enum): FOO = auto() The reason I ask is that I have two functions that take an enum argument. The first takes one

Re: Enum questions.

2016-04-13 Thread Ethan Furman
On 04/13/2016 07:21 AM, Ethan Furman wrote: On 04/13/2016 07:07 AM, Marko Rauhamaa wrote: class Color(enum.Enum): red blue green This last one is to the point but raises a NameError. Using the aenum library that last one is possible. It also has NamedConstan

Re: Enum questions.

2016-04-13 Thread Ethan Furman
On 04/13/2016 07:07 AM, Marko Rauhamaa wrote: class Color(enum.Enum): red blue green This last one is to the point but raises a NameError. Using the aenum library that last one is possible. It also has NamedConstant and a metaclass-derived NamedTuple! --

Re: Enum questions.

2016-04-13 Thread Ian Kelly
On Wed, Apr 13, 2016 at 7:50 AM, Grant Edwards wrote: > FWIW, as an old Pascal programmer, I too would have been surprised > that an "enum" is not ordinal and doesn't support a next/prev and > iteration. They do support iteration, but it's by order of declaration, not by value. -- https://mail.p

Re: Enum questions.

2016-04-13 Thread Marko Rauhamaa
Grant Edwards : > On 2016-04-13, Michael Selik wrote: >> An Enum corresponds to "nominal" data that is coded as a number >> simply for storage rather than meaning. > > FWIW, as an old Pascal programmer, I too would have been surprised > that an "enum" is not ordinal and doesn't support a next/pre

Re: Enum questions.

2016-04-13 Thread Grant Edwards
On 2016-04-13, Michael Selik wrote: > On Wed, Apr 13, 2016, 12:14 PM Antoon Pardon > wrote: > >> I have been looking at the enum documentation and it seems enums >> are missing two features I rather find important. >> >> 1) Given an Enum value, someway to get the next/previous >>one >> >> 2)

Re: Enum questions.

2016-04-13 Thread Rustom Mody
On Wednesday, April 13, 2016 at 5:39:13 PM UTC+5:30, Michael Selik wrote: > On Wed, Apr 13, 2016, 12:14 PM Antoon Pardon > wrote: > > > I have been looking at the enum documentation and it > > seems enums are missing two features I rather find > > important. > > > > 1) Given an Enum value, someway

Re: Enum questions.

2016-04-13 Thread Michael Selik
On Wed, Apr 13, 2016, 12:14 PM Antoon Pardon wrote: > I have been looking at the enum documentation and it > seems enums are missing two features I rather find > important. > > 1) Given an Enum value, someway to get the next/previous >one > > 2) Given two Enum values, iterate over the values

Re: Enum questions.

2016-04-13 Thread jmp
On 04/13/2016 12:12 PM, Antoon Pardon wrote: I have been looking at the enum documentation and it seems enums are missing two features I rather find important. 1) Given an Enum value, someway to get the next/previous one 2) Given two Enum values, iterate over the values between them. D

Re: Enum questions.

2016-04-13 Thread Marko Rauhamaa
Rustom Mody : > Given the eg in the docs: > from enum import Enum > class Color(Enum): > red = 1 > blue = 2 > green = 3 > Color(Color.red.value+1) > But: >>> class Color(enum.Enum): ... red = 0xff ... green = 0x00ff00 ... blue = 0xff ... >>> Colo

Re: Enum questions.

2016-04-13 Thread Rustom Mody
On Wednesday, April 13, 2016 at 3:43:41 PM UTC+5:30, Antoon Pardon wrote: > I have been looking at the enum documentation and it > seems enums are missing two features I rather find > important. > > 1) Given an Enum value, someway to get the next/previous >one > > 2) Given two Enum values, it

RE: Enum class

2015-10-15 Thread Joseph L. Casale
> Like that? > > >>> class M2(enum.EnumMeta): >... def __contains__(self, value): >... print(value, "? never", sep="") >... return False >... > >>> Colors.__class__ > > >>> Colors.red in Colors > checking Colors.red > True > >>> Colors.__class__ = M2 > >>> Colors.red in Colors

Re: Enum class

2015-10-15 Thread Peter Otten
Joseph L. Casale wrote: > import enum > class M(enum.EnumMeta): >>... def __contains__(self, value): >>... print("checking", value) >>... return super().__contains__(value) >>... > class Colors(enum.Enum, metaclass=M): >>... red = 1 >>... green = 2 >>...

Re: Enum class

2015-10-15 Thread Joseph L. Casale
import enum class M(enum.EnumMeta): >... def __contains__(self, value): >... print("checking", value) >... return super().__contains__(value) >... class Colors(enum.Enum, metaclass=M): >... red = 1 >... green = 2 >... blue = 3 >... Colors.red in C

Re: Enum class

2015-10-15 Thread Peter Otten
Joseph L. Casale wrote: > Is it possible to override __contains__ from the meta class in the derived > class with the Enum type? >>> import enum >>> class M(enum.EnumMeta): ... def __contains__(self, value): ... print("checking", value) ... return super().__contains__(value) .

Re: Enum vs OrderedEnum

2013-08-07 Thread Neil Cerutti
On 2013-08-07, Ian Kelly wrote: > On Tue, Aug 6, 2013 at 7:55 PM, Ben Finney wrote: >> Ian Kelly writes: >> Terrain that is ?radiated? would be terrain that has some kind of spokes >> spreading out from its centre. I think you mean ?irradiated?. >> >> Hope the game goes well :-) > > It's actuall

Re: Enum vs OrderedEnum

2013-08-07 Thread Ian Kelly
On Tue, Aug 6, 2013 at 6:33 PM, Ethan Furman wrote: > class Environment(AutoNumber): > > gaia = 2.0 > fertile = 1.5 > terran = 1.0 > jungle = 1.0 > ocean = 1.0 > arid = 1.0 > steppe = 1.0 > desert = 1.0 > minimal = 1.0 > barren = 0.5 > tundra = 0.5 >

Re: Enum vs OrderedEnum

2013-08-07 Thread Ian Kelly
On Tue, Aug 6, 2013 at 7:55 PM, Ben Finney wrote: > Ian Kelly writes: > Terrain that is “radiated” would be terrain that has some kind of spokes > spreading out from its centre. I think you mean “irradiated”. > > Hope the game goes well :-) It's actually a reimplementation of a game from 1993, s

Re: Enum vs OrderedEnum

2013-08-06 Thread Ben Finney
Ian Kelly writes: > class Environment(OrderedEnum): I have nothing to add regarding the Python code, but I wanted to make a language correction: > gaia = 1 > fertile = 2 > terran, jungle, ocean, arid, steppe, desert, minimal = range(3, 10) > barren, tundra, dead, inferno, toxic,

Re: Enum vs OrderedEnum

2013-08-06 Thread Ethan Furman
On 08/06/2013 04:46 PM, Ian Kelly wrote: On Aug 6, 2013 5:15 PM, "Ethan Furman" mailto:et...@stoneleaf.us>> wrote: Use the .value attribute instead. You could also substitute self for Environment. It feels more natural and readable to compare the enum instances rather than their value att

Re: Enum vs OrderedEnum

2013-08-06 Thread Rhodri James
On Wed, 07 Aug 2013 00:46:39 +0100, Ian Kelly wrote: On Aug 6, 2013 5:15 PM, "Ethan Furman" wrote: Use the .value attribute instead. You could also substitute self for Environment. It feels more natural and readable to compare the enum instances rather than their value attributes. If I

Re: Enum vs OrderedEnum

2013-08-06 Thread Ian Kelly
On Aug 6, 2013 5:15 PM, "Ethan Furman" wrote: > > Use the .value attribute instead. You could also substitute self for Environment. It feels more natural and readable to compare the enum instances rather than their value attributes. If I am ordering the values then that seems to imply that the e

Re: Enum vs OrderedEnum

2013-08-06 Thread Ethan Furman
On 08/06/2013 04:00 PM, Ian Kelly wrote: Use the .value attribute instead. You could also substitute self for Environment. class Environment(Enum): gaia = 1 fertile = 2 terran, jungle, ocean, arid, steppe, desert, minimal = range(3, 10) barren, tundra, dead, inferno, tox

Re: Enum class with ToString functionality

2007-09-12 Thread Neil Cerutti
On 2007-09-11, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > Perhaps Ben should have followed the usual practice of > commercial, closed- source software developers and started > counting his version numbers at one instead of zero, miss a few > releases, use randomly large increments occasionally, a

Re: Enum class with ToString functionality

2007-09-11 Thread Steven D'Aprano
On Mon, 10 Sep 2007 18:03:11 -0700, TheFlyingDutchman wrote: >> I'd like to know if the Cheeseshop package 'enum' is useful to you. Any >> constructive feedback would be appreciated. >> >> http://cheeseshop.python.org/pypi/enum/> > > Looking at the documentation it looks excellent. But I don'

Re: Enum class with ToString functionality

2007-09-11 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > Hi, > > I have the following class - > > class TestOutcomes: > PASSED = 0 > FAILED = 1 > ABORTED = 2 > > plus the following code - > > testResult = TestOutcomes.PASSED > > testResultAsString > if testResult == TestOutcomes.PASSED: > testResultAsStrin

Re: Enum class with ToString functionality

2007-09-11 Thread J. Cliff Dyer
Zara wrote: > On Mon, 10 Sep 2007 02:28:57 -0700, [EMAIL PROTECTED] wrote: > > >> Hi, >> >> I have the following class - >> >> class TestOutcomes: >>PASSED = 0 >>FAILED = 1 >>ABORTED = 2 >> >> plus the following code - >> >> testResult = TestOutcomes.PASSED >> >> testResultAsString >

Re: Enum class with ToString functionality

2007-09-10 Thread Zara
On Mon, 10 Sep 2007 02:28:57 -0700, [EMAIL PROTECTED] wrote: >Hi, > >I have the following class - > >class TestOutcomes: >PASSED = 0 >FAILED = 1 >ABORTED = 2 > >plus the following code - > >testResult = TestOutcomes.PASSED > >testResultAsString >if testResult == TestOutcomes.PASSED: >

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
On Sep 10, 7:55 pm, "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote: > TheFlyingDutchman wrote: > > On Sep 10, 7:12 pm, Ben Finney <[EMAIL PROTECTED]> > > wrote: > >> TheFlyingDutchman <[EMAIL PROTECTED]> writes: > http://cheeseshop.python.org/pypi/enum/> > >> (Please preserve attribution lines so

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
On Sep 10, 8:02 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > TheFlyingDutchman <[EMAIL PROTECTED]> writes: > > On Sep 10, 7:12 pm, Ben Finney <[EMAIL PROTECTED]> > > wrote: > > > TheFlyingDutchman <[EMAIL PROTECTED]> writes: > > > > Looking at the documentation it looks excellent. But I don't > > >

Re: Enum class with ToString functionality

2007-09-10 Thread Ben Finney
TheFlyingDutchman <[EMAIL PROTECTED]> writes: > On Sep 10, 7:12 pm, Ben Finney <[EMAIL PROTECTED]> > wrote: > > TheFlyingDutchman <[EMAIL PROTECTED]> writes: > > > Looking at the documentation it looks excellent. But I don't > > > understand the 0.4.2 version number, > > > > Note the tag that says

Re: Enum class with ToString functionality

2007-09-10 Thread J. Cliff Dyer
TheFlyingDutchman wrote: > On Sep 10, 7:12 pm, Ben Finney <[EMAIL PROTECTED]> > wrote: >> TheFlyingDutchman <[EMAIL PROTECTED]> writes: http://cheeseshop.python.org/pypi/enum/> >> (Please preserve attribution lines so it's clear who wrote what.) >> >> >>> Looking at the documentation it look

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
On Sep 10, 7:12 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > TheFlyingDutchman <[EMAIL PROTECTED]> writes: > > > http://cheeseshop.python.org/pypi/enum/> > > (Please preserve attribution lines so it's clear who wrote what.) > > > Looking at the documentation it looks excellent. But I don't > > u

Re: Enum class with ToString functionality

2007-09-10 Thread Ben Finney
TheFlyingDutchman <[EMAIL PROTECTED]> writes: > > http://cheeseshop.python.org/pypi/enum/> (Please preserve attribution lines so it's clear who wrote what.) > Looking at the documentation it looks excellent. But I don't > understand the 0.4.2 version number, Note the tag that says the "Deve

Re: Enum class with ToString functionality

2007-09-10 Thread Bruno Desthuilliers
TheFlyingDutchman a écrit : > On Sep 8, 9:52 am, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote: > >>TheFlyingDutchman a écrit : (snip) >>>class TestOutcomes: >>>PASSED = 0 >>>FAILED = 1 >>>ABORTED = 2 >> >>>def ToString(outcome): >>>if outcome == TestOutcomes.PASSED: >>>

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
> > I'd like to know if the Cheeseshop package 'enum' is useful to > you. Any constructive feedback would be appreciated. > > http://cheeseshop.python.org/pypi/enum/> Looking at the documentation it looks excellent. But I don't understand the 0.4.2 version number, particularly when you refer

Re: Enum class with ToString functionality

2007-09-10 Thread Ben Finney
[EMAIL PROTECTED] writes: > But it would be much nicer if I had a function to covert to string > as part of the TestOutcomes class. How would I implement this? Others have given ad hoc implementations that may do what you want. I'd like to know if the Cheeseshop package 'enum' is useful to you.

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
On Sep 8, 9:52 am, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > TheFlyingDutchman a écrit : > > > > > On Sep 10, 2:28 am, [EMAIL PROTECTED] wrote: > > >>Hi, > > >>I have the following class - > > >>class TestOutcomes: > >>PASSED = 0 > >>FAILED = 1 > >>ABORTED = 2 > > >>plus the foll

Re: Enum class with ToString functionality

2007-09-10 Thread Bruno Desthuilliers
TheFlyingDutchman a écrit : > On Sep 10, 2:28 am, [EMAIL PROTECTED] wrote: > >>Hi, >> >>I have the following class - >> >>class TestOutcomes: >>PASSED = 0 >>FAILED = 1 >>ABORTED = 2 >> >>plus the following code - >> >>testResult = TestOutcomes.PASSED >> >>testResultAsString >>if testR

Re: Enum class with ToString functionality

2007-09-10 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote: > I have the following class - > > class TestOutcomes: > PASSED = 0 > FAILED = 1 > ABORTED = 2 > > plus the following code - > > testResult = TestOutcomes.PASSED > > testResultAsString > if testResult == TestOutcomes.PASSED: > testResultAsString = "Pas

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
On Sep 10, 2:28 am, [EMAIL PROTECTED] wrote: > Hi, > > I have the following class - > > class TestOutcomes: > PASSED = 0 > FAILED = 1 > ABORTED = 2 > > plus the following code - > > testResult = TestOutcomes.PASSED > > testResultAsString > if testResult == TestOutcomes.PASSED: > te

Re: Enum class with ToString functionality

2007-09-10 Thread David
On 9/10/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi, > > I have the following class - > > class TestOutcomes: > PASSED = 0 > FAILED = 1 > ABORTED = 2 > > plus the following code - > > testResult = TestOutcomes.PASSED > > testResultAsString > if testResult == TestOutcomes.PASS

Re: Enum class with ToString functionality

2007-09-10 Thread aine_canby
On 10 Sep, 13:35, TheFlyingDutchman <[EMAIL PROTECTED]> wrote: > On Sep 10, 2:28 am, [EMAIL PROTECTED] wrote: > > > > > > > Hi, > > > I have the following class - > > > class TestOutcomes: > > PASSED = 0 > > FAILED = 1 > > ABORTED = 2 > > > plus the following code - > > > testResult = T

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
On Sep 10, 2:28 am, [EMAIL PROTECTED] wrote: > Hi, > > I have the following class - > > class TestOutcomes: > PASSED = 0 > FAILED = 1 > ABORTED = 2 > > plus the following code - > > testResult = TestOutcomes.PASSED > > testResultAsString > if testResult == TestOutcomes.PASSED: > te

Re: Enum class with ToString functionality

2007-09-10 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > But it would be much nicer if I had a function to covert to string as > part of the TestOutcomes class. How would I implement this? Perhaps: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486 -- http://mail.python.org/mailman/listinfo/python-list

Re: enum question

2005-03-09 Thread Terry Hancock
On Friday 04 March 2005 02:54 pm, M.N.A.Smadi wrote: > does python support a C-like enum statement where one can define a > variable with prespesified range of values? No, but in most situations where I would've used an enum, I use a trivial class like this: class states: ON, OFF, UNKNOWN,

Re: enum question

2005-03-05 Thread Carl Banks
M.N.A.Smadi wrote: > does python support a C-like enum statement where one can define a > variable with prespesified range of values? The thing is, variables don't have types; objects do. A variable can be bound to an object of any type, so there's no way to prespecify a range of values for a va

Re: enum question

2005-03-05 Thread Patrick Useldinger
M.N.A.Smadi wrote: does python support a C-like enum statement where one can define a variable with prespesified range of values? thanks m.smadi >>> BLUE, RED, GREEN = 1,5,8 >>> BLUE 1 >>> RED 5 >>> GREEN 8 -- http://mail.python.org/mailman/listinfo/python-list

Re: enum question

2005-03-05 Thread Stephen Toledo-Brown
M.N.A.Smadi wrote: does python support a C-like enum statement where one can define a variable with prespesified range of values? Not built in, but there are various solutions available, some simpler than others. See the Infrequently Asked Questions: http://www.norvig.com/python-iaq.html -- Ste

Re: enum question

2005-03-04 Thread Larry Bates
Not completely sure I understand (my C is weak). But you can do: x=range(9) x's contents will be [0,1,2,3,4,5,6,7,8] or x=range(12,25) x's conetnst will be [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] if you mean a way to limit x's contents to a predefined list of values, you need to