[issue23591] enum: Add Flags and IntFlags

2016-11-21 Thread Roundup Robot
Roundup Robot added the comment: New changeset f404a59d834e by Ethan Furman in branch '3.6': closes issue23591: add NEWS entry https://hg.python.org/cpython/rev/f404a59d834e -- status: open -> closed ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-09-26 Thread Josh Rosenberg
Josh Rosenberg added the comment: The "What’s New In Python 3.6" page should really get an update to mention Flag, IntFlag and auto as enhancements to the enum module. Right now, the ssl module update docs mentions (but does not properly link for some reason) IntFlag, but otherwise, there is

[issue23591] enum: Add Flags and IntFlags

2016-09-18 Thread Roundup Robot
Roundup Robot added the comment: New changeset b56290a80ff7 by Ethan Furman in branch '3.6': issue23591: fix flag decomposition and repr https://hg.python.org/cpython/rev/b56290a80ff7 New changeset 7372c042e9a1 by Ethan Furman in branch 'default': issue23591: fix flag decomposition and repr

[issue23591] enum: Add Flags and IntFlags

2016-09-13 Thread Ethan Furman
Ethan Furman added the comment: I'll respond to the bulk of your comment later. For now let me assure you your feedback has been invaluable. -- ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-09-13 Thread Vedran Čačić
Vedran Čačić added the comment: About drama: I don't know how to approach the problem. I tell you about various concerns of mine, you seem to agree, and still you do exactly what I was warning you about. It could be that you just consider me a boring nag, but then saying so would be more

[issue23591] enum: Add Flags and IntFlags

2016-09-13 Thread Ethan Furman
Ethan Furman added the comment: Vedran: 1) Thank you for the bug report, it's appreciated. 2) I would appreciate it even more if you just kept it to a bug report without the, for lack of a better word, drama. --- >>>> import enum >>>>

[issue23591] enum: Add Flags and IntFlags

2016-09-13 Thread Vedran Čačić
Vedran Čačić added the comment: Now that I actually had the chance to play with the implementation, I see most of my worst fears were justified. :-( Look: >>> import enum >>> class B(enum.Flag): b = 3 c = 4 d = 6 >>> B.b | B.c Traceback (most

[issue23591] enum: Add Flags and IntFlags

2016-09-11 Thread Ethan Furman
Ethan Furman added the comment: Many thanks to everyone for their input and help. -- resolution: -> fixed stage: commit review -> resolved status: open -> closed ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-09-11 Thread Ethan Furman
Ethan Furman added the comment: >> Which means it has methods such as __getitem__, __setitem__, etc., >> which means those methods can implement whatever is needed to give >> the namespace the desired semantics (within Python syntax). > Ah, _that_'s what you had in mind. (All this time, I

[issue23591] enum: Add Flags and IntFlags

2016-09-11 Thread Vedran Čačić
Vedran Čačić added the comment: > Which means it has methods such as __getitem__, __setitem__, etc., which > means those methods can implement whatever is needed to give the namespace > the desired semantics (within Python syntax). Ah, _that_'s what you had in mind. (All this time, I thought

[issue23591] enum: Add Flags and IntFlags

2016-09-11 Thread Ethan Furman
Changes by Ethan Furman : -- stage: patch review -> commit review ___ Python tracker ___

[issue23591] enum: Add Flags and IntFlags

2016-09-11 Thread Roundup Robot
Roundup Robot added the comment: New changeset aad7443e62be by Ethan Furman in branch 'default': issue23591: add auto() for auto-generating Enum member values https://hg.python.org/cpython/rev/aad7443e62be -- ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-09-08 Thread Ethan Furman
Ethan Furman added the comment: Just so we're clear: I'm going to go with "auto()" and (mostly) use Python's standard routines (with only a little bit of metaclass magic). Vedran opined: > Since you like examples, what do you say about I love examples! Examples are like pictures, which are

[issue23591] enum: Add Flags and IntFlags

2016-09-08 Thread Vedran Čačić
Vedran Čačić added the comment: Since you like examples, what do you say about class MyEnum(Enum): red = some_function() blue = red Now, is MyEnum.blue the same as MyEnum.red (watch: not "equal", but "same")? Well, it depends on what some_function returns, right? If it

[issue23591] enum: Add Flags and IntFlags

2016-09-08 Thread Vedran Čačić
Vedran Čačić added the comment: Yes, I didn't explain well. I'm ok with postprocessing. After all, since we got PEP 520, it's quite obvious that "the namespace class body is executed in" is not the same as "the final __dict__ of a class". But even "the namespace class body is executed in"

[issue23591] enum: Add Flags and IntFlags

2016-09-08 Thread Martin Panter
Changes by Martin Panter : -- nosy: -martin.panter ___ Python tracker ___ ___

[issue23591] enum: Add Flags and IntFlags

2016-09-08 Thread Ethan Furman
Ethan Furman added the comment: Vedran commented: > This is something fundamental: it is breaking the promise that class body > is a suite of commands, where Python statements (such as assignment) have > their usual semantics. I find it curious that you're okay with >>> class Color(Enum): ...

[issue23591] enum: Add Flags and IntFlags

2016-09-07 Thread Raymond Hettinger
Raymond Hettinger added the comment: > Any problems with: > > class Color(Enum): # or Color(Flag) > red = _auto_ > green = _auto_ > blue = _auto_ As long as _auto_ has been defined somewhere (i.e. from enum import _auto_), it is normal Python and doesn't fight with the rest of language or

[issue23591] enum: Add Flags and IntFlags

2016-09-07 Thread Vedran Čačić
Vedran Čačić added the comment: _member_() is fine with me, though I prefer _auto_(). _auto_member_() is probably too much. :-) The argument "we already do magic, so let's do also this bit of non-connected magic" seems very weak to me. But in fact those other things are not _magic_ in the

[issue23591] enum: Add Flags and IntFlags

2016-09-07 Thread Ethan Furman
Ethan Furman added the comment: > For me, it is an issue. But you probably already know that. >(http://bugs.python.org/issue26988#msg273125) (That's "the other thread".) Ah, thanks. I had forgotten about that one. For what it's worth, I largely agree with you there. > Try to explain: how

[issue23591] enum: Add Flags and IntFlags

2016-09-07 Thread Vedran Čačić
Vedran Čačić added the comment: For me, it is an issue. But you probably already know that. (http://bugs.python.org/issue26988#msg273125) (That's "the other thread".) Try to explain: how exactly is that different than wanting "file.close" to close the file, or "quit" to quit the REPL? And I

[issue23591] enum: Add Flags and IntFlags

2016-09-07 Thread Ethan Furman
Ethan Furman added the comment: Any problems with: class Color(Enum): # or Color(Flag) red = _auto_ green = _auto_ blue = _auto_ In other words: - is the missing parenthesis an issue? - are linters/checkers/IDEs going to have (or report) problems with that? --

[issue23591] enum: Add Flags and IntFlags

2016-09-07 Thread Ethan Furman
Ethan Furman added the comment: I like it! (Although I have no idea which other thread you are talking about.) And yes, it needs the leading and trailing underscore so as not to clash with member names. -- ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-09-07 Thread Vedran Čačić
Vedran Čačić added the comment: I think we had that discussion in the other thread, and concluded that auto() (or _auto_() if you insist) is quite fine. I think it's important to emphasize it's automatically generated, not that it's really "next" in any particular order. --

[issue23591] enum: Add Flags and IntFlags

2016-09-07 Thread STINNER Victor
Changes by STINNER Victor : -- nosy: -haypo ___ Python tracker ___ ___

[issue23591] enum: Add Flags and IntFlags

2016-09-07 Thread Ethan Furman
Ethan Furman added the comment: I would like to add a function that can be used when creating a Flag (and Enum, but that's less important) that will generate the next value. This is important because in Flag the values are an important internal detail, but are largely irrelevant to the user

[issue23591] enum: Add Flags and IntFlags

2016-09-05 Thread Ethan Furman
Ethan Furman added the comment: > I am quite aware about what's the intended use, but you can't just > assume people will know about it. Fair enough. > In my view, you must do one of two things: > > 1) (at least in documentation, and preferably in the code by raising > Exceptions at class

[issue23591] enum: Add Flags and IntFlags

2016-09-04 Thread Vedran Čačić
Vedran Čačić added the comment: > As a side note, I suspect there would be much less confusion with Flag if we > had an AutoEnum. No, there would be _different_ confusion. :-P Anyway, let's get back to the discussion. I am quite aware about what's the intended use, but you can't just assume

[issue23591] enum: Add Flags and IntFlags

2016-09-04 Thread Roundup Robot
Roundup Robot added the comment: New changeset 8e9d3a5d47d5 by Ethan Furman in branch 'default': issue23591: more docs; slight change to repr https://hg.python.org/cpython/rev/8e9d3a5d47d5 -- ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-09-04 Thread Ethan Furman
Ethan Furman added the comment: As a side note, I suspect there would be much less confusion with Flag if we had an AutoEnum. C'est la vie. -- ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-09-04 Thread Ethan Furman
Ethan Furman added the comment: > All my questions pertain to Flags. Ah, okay. > You said what to me seem like two contradictory things: > >> Not having 2 named has different consequences for Flag vs IntFlag >> (although *neither is an error*): Flag: no combination of flags will >> ever have

[issue23591] enum: Add Flags and IntFlags

2016-09-04 Thread Vedran Čačić
Vedran Čačić added the comment: Ok, I believe you that you have the interface for IntFlags right (I always did, and I apologize if I didn't make it clear from the start). All my questions pertain to Flags. You said what to me seem like two contradictory things: > Not having 2 named has

[issue23591] enum: Add Flags and IntFlags

2016-09-03 Thread Ethan Furman
Ethan Furman added the comment: > 1) IntFlags is not simply the meet of int and Flags (like IntEnum is the > meet of int and Enum, > https://docs.python.org/3.5/library/enum.html#others)? > It seems a very different class. No, I think it is. The differences between Enum and IntEnum are

[issue23591] enum: Add Flags and IntFlags

2016-09-03 Thread Vedran Čačić
Vedran Čačić added the comment: Hmm... so if I read you right: 1) IntFlags is not simply the meet of int and Flags (like IntEnum is the meet of int and Enum, https://docs.python.org/3.5/library/enum.html#others)? It seems a very different class. 2) (more important) If I give names to 1, 3,

[issue23591] enum: Add Flags and IntFlags

2016-09-02 Thread Roundup Robot
Roundup Robot added the comment: New changeset f33fc2117bb2 by Ethan Furman in branch 'default': issue23591: bool(empty_flags) == False; more docs & tests https://hg.python.org/cpython/rev/f33fc2117bb2 -- ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-09-02 Thread Roundup Robot
Roundup Robot added the comment: New changeset 31586a2f01b6 by Ethan Furman in branch 'default': issue23591: optimize _high_bit() https://hg.python.org/cpython/rev/31586a2f01b6 -- ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-09-02 Thread Ethan Furman
Ethan Furman added the comment: > Yes, you're correct here, but what about output? Do all relevant bits have > to be named separately? No. > And will the output always talk about separate > bits? No. > We have talked about this. Indeed. Here's my previous reply. ;) >> The algorithm is

[issue23591] enum: Add Flags and IntFlags

2016-09-02 Thread Vedran Čačić
Vedran Čačić added the comment: > Nope. You are welcome to give more meaningful names to different > combinations of powers of two. Yes, you're correct here, but what about output? Do all relevant bits have to be named separately? And will the output always talk about separate bits? We have

[issue23591] enum: Add Flags and IntFlags

2016-09-02 Thread Roundup Robot
Roundup Robot added the comment: New changeset adbc7eec97f1 by Ethan Furman in branch 'default': issue23591: add docs; code cleanup; more tests https://hg.python.org/cpython/rev/adbc7eec97f1 -- ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-09-01 Thread Vedran Čačić
Vedran Čačić added the comment: Sure, errors should never pass silently. This function shouldn't be called with nonpositive arguments. And there is no highbit of 0 (and there are infinitely many of negative numbers;). ValueError is probably best - though IndexError can also be argued for,

[issue23591] enum: Add Flags and IntFlags

2016-09-01 Thread STINNER Victor
STINNER Victor added the comment: As noticed by veky on the review, _high_bit() is slow and can be optimized using int.bit_length(). Attached bit_length.patch implements this. _high_bit(0) returns -1. Maybe an exception must be raised if the argument is < 1? (also fail for negative number)

[issue23591] enum: Add Flags and IntFlags

2016-08-31 Thread Raymond Hettinger
Raymond Hettinger added the comment: Still needs docs. -- ___ Python tracker ___ ___ Python-bugs-list mailing

[issue23591] enum: Add Flags and IntFlags

2016-08-31 Thread Roundup Robot
Roundup Robot added the comment: New changeset 39661e2ff030 by Ethan Furman in branch 'default': issue23591: add Flags, IntFlags, and tests https://hg.python.org/cpython/rev/39661e2ff030 -- nosy: +python-dev ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-08-30 Thread Ethan Furman
Ethan Furman added the comment: Since we're using re as the sample, here's where re.I is defined: Lib/re.py: - I = IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case As already mentioned, re.I results in 2, and a re.compile object is not usable as a re flag. > Also, I suppose

[issue23591] enum: Add Flags and IntFlags

2016-08-30 Thread Vedran Čačić
Vedran Čačić added the comment: The weirdest thing is that it already works pretty well in output of re.compile. >>> re.compile('', re.I | re.M) re.compile('', re.IGNORECASE|re.MULTILINE) >>> _.flags # re.UNICODE == 32 added automatically 42 So the only thing we should enhance

[issue23591] enum: Add Flags and IntFlags

2016-08-30 Thread Ethan Furman
Ethan Furman added the comment: Raymond, thanks for your support. I am happy to have a flags variant. The advice to wait and let Enum mature instead of adding the Flag variant at the beginning was sound, and we have a better product to show for it now. The four base Enum-type classes will

[issue23591] enum: Add Flags and IntFlags

2016-08-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: [Ethan] > My experience is that a module maintainer, or somebody claiming to speak > for the module maintainer, can close any issue in their area at any > time regardless of the number of core devs in favor of a change. Ethan, it is still up to you and the

[issue23591] enum: Add Flags and IntFlags

2016-08-30 Thread Ethan Furman
Ethan Furman added the comment: Patch includes tests, but not docs. >From a previous comment: --- > As it stands, Weird(7) would be , and if A was not > defined an error would be raised. Actually, it would be since BC has a higher value than

[issue23591] enum: Add Flags and IntFlags

2016-08-17 Thread STINNER Victor
STINNER Victor added the comment: > The repr is better -- which patch did you test? Sorry, I wasn't clear. I didn't test any patch :-) I expect (not expected) better repr when changes will be applied, it's just a remark... -- ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-08-17 Thread Ethan Furman
Ethan Furman added the comment: The repr is better -- which patch did you test? -- ___ Python tracker ___ ___

[issue23591] enum: Add Flags and IntFlags

2016-08-17 Thread STINNER Victor
STINNER Victor added the comment: I expected better repr for such code: >>> socket.SOCK_STREAM | socket.SOCK_CLOEXEC 524289 >>> os.O_RDONLY | os.O_APPEND 1024 -- ___ Python tracker

[issue23591] enum: Add Flags and IntFlags

2016-08-17 Thread STINNER Victor
STINNER Victor added the comment: I really like the idea of IntFlags. -- nosy: +haypo title: Add Flags and IntFlags -> enum: Add Flags and IntFlags ___ Python tracker