[Python-Dev] Re: containment and the empty container

2021-11-11 Thread Ethan Furman
On 11/9/21 9:02 AM, Guido van Rossum wrote: > On Mon, Nov 8, 2021 at 10:29 PM Ethan Furman wrote: >> The way I see it, the following should hold >> >> empty_flag = RegexFlag(0) >> any_case = RegexFlag.IGNORECASE >> any_case_on_any_line = RegexFlag.IGNORECASE | RegexF

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Chris Angelico
On Wed, Nov 10, 2021 at 11:44 AM Ethan Furman wrote: > I don't know if there's a formal name, but in my mind, if you have something > you don't have nothing. If you have a > barrel with nothing in it (not even air, just a hard vacuum) then saying you > have nothing in that barrel is a true > st

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Ethan Furman
On 11/8/21 3:09 PM, Steven D'Aprano wrote: > On Mon, Nov 08, 2021 at 01:43:03PM -0800, Ethan Furman wrote: >> SomeFlag.nothing in SomeFlag.something <-- ??? > > I don't think that consistency with other containers is particularly > relevant here. More useful is consistency with other flag objec

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Guido van Rossum
On Mon, Nov 8, 2021 at 10:29 PM Ethan Furman wrote: > > The way I see it, the following should hold > > empty_flag = RegexFlag(0) > any_case = RegexFlag.IGNORECASE > any_case_on_any_line = RegexFlag.IGNORECASE | RegexFlag.MULTILINE > > any_case in empty_flag is False > an

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Stephen J. Turnbull
Cameron Simpson writes: > On 08Nov2021 23:32, MRAB wrote: > >A flag could be a member, but could a set of flags? > > Probably one flavour should raise a TypeError then with this comparison. > I wouldn't want "member flag present in SomeFlag.something" and > "set-of-members present in So

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Stephen J. Turnbull
Tim Peters writes: > [Ethan Furman ] > > .. on the other hand, it seems that collections of related flags > > are often treated as in set theory, where the empty set is a > > member of any non-empty set. > > Not how any set theory I've ever seen works: a set S contains the > empty set if a

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Greg Ewing
On 9/11/21 7:29 pm, Ethan Furman wrote: I've had a couple people tell me that they think of flags as sets, and use set theory / set behavior to understand how flags and groups of flags should interact. If you're going to think of flags as sets, then 'i in flags' should be equivalent to '((1 <<

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Paul Moore
On Tue, 9 Nov 2021 at 06:31, Ethan Furman wrote: (IMO, Steven D'Aprano's comment above, which I don't think you have responded to yet, is the clearest summary of the options here. I agree with what he says, but just wanted to clarify one point below). > I've had a couple people tell me that they

[Python-Dev] Re: containment and the empty container

2021-11-08 Thread Rob Cliffe via Python-Dev
On 08/11/2021 21:43, Ethan Furman wrote: When is an empty container contained by a non-empty container? For example: These examples are not at all analogous.  `a in b` has different meanings for different classes of b. {} in {1:'a', 'b':2]   <-- TypeError because of hashability `x in aDict`

[Python-Dev] Re: containment and the empty container

2021-11-08 Thread Ethan Furman
Something to keep in mind as these discussions continue: Enums are already unusual in several ways: - the class itself is iterable - the class itself supports containment checks of its enum members - the enum members are created, and guaranteed singletons, during class creation - the enum membe

[Python-Dev] Re: containment and the empty container

2021-11-08 Thread Guido van Rossum
On Mon, Nov 8, 2021 at 7:26 PM Ethan Furman wrote: > Let's use a concrete example: `re.RegexFlag` > > ``` > Help on function match in module re: > > match(pattern, string, flags=0) > Try to apply the pattern at the start of the string, returning > a Match object, or None if no match wa

[Python-Dev] Re: containment and the empty container

2021-11-08 Thread Ethan Furman
Let's use a concrete example: `re.RegexFlag` ``` Help on function match in module re: match(pattern, string, flags=0) Try to apply the pattern at the start of the string, returning a Match object, or None if no match was found. ``` In use we have: result = re.match('present', 'who

[Python-Dev] Re: containment and the empty container

2021-11-08 Thread John Melendowski
I think he's confusing the fact that empty is a subset of every set ___ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message arch

[Python-Dev] Re: containment and the empty container

2021-11-08 Thread Guido van Rossum
On Mon, Nov 8, 2021 at 1:43 PM Ethan Furman wrote: > When is an empty container contained by a non-empty container? > > For example: > > {} in {1:'a', 'b':2} <-- TypeError because of hashability > (You accidentally wrote a square close bracket, but I know you meant a curly close brace. :-} >

[Python-Dev] Re: containment and the empty container

2021-11-08 Thread MRAB
On 2021-11-09 00:27, Cameron Simpson wrote: On 08Nov2021 23:32, MRAB wrote: >On 2021-11-08 22:10, Cameron Simpson wrote: >>>{} in {1:'a', 'b':2] <-- TypeError because of hashability >>>set() in {1, 2, 'a', 'b'} <-- ditto >>>[] in ['a', 'b', 1, 2] <-- False >> >>Right. Also, the members are n

[Python-Dev] Re: containment and the empty container

2021-11-08 Thread Cameron Simpson
On 08Nov2021 23:32, MRAB wrote: >On 2021-11-08 22:10, Cameron Simpson wrote: >>>{} in {1:'a', 'b':2] <-- TypeError because of hashability >>>set() in {1, 2, 'a', 'b'} <-- ditto >>>[] in ['a', 'b', 1, 2] <-- False >> >>Right. Also, the members are not dicts or sets, respectively. >> >More preci

[Python-Dev] Re: containment and the empty container

2021-11-08 Thread MRAB
On 2021-11-08 22:10, Cameron Simpson wrote: Note: I know you understand all this, I'm not "explaining" how things work below, I'm explaining how/why I think about how these work. On 08Nov2021 13:43, Ethan Furman wrote: When is an empty container contained by a non-empty container? [...] For

[Python-Dev] Re: containment and the empty container

2021-11-08 Thread Steven D'Aprano
On Mon, Nov 08, 2021 at 01:43:03PM -0800, Ethan Furman wrote: > When is an empty container contained by a non-empty container? [...] > SomeFlag.nothing in SomeFlag.something <-- ??? I don't think that consistency with other containers is particularly relevant here. More useful is consistency w

[Python-Dev] Re: containment and the empty container

2021-11-08 Thread Tim Peters
[Ethan Furman ] > When is an empty container contained by a non-empty container? That depends on how the non-empty container's type defines __contains__. The "stringish" types (str, byte, bytearray) work _very_ differently from others (list, set, tuple) in this respect. t in x for the latter

[Python-Dev] Re: containment and the empty container

2021-11-08 Thread Cameron Simpson
Note: I know you understand all this, I'm not "explaining" how things work below, I'm explaining how/why I think about how these work. On 08Nov2021 13:43, Ethan Furman wrote: >When is an empty container contained by a non-empty container? [...] >For example: > >{} in {1:'a', 'b':2] <-- TypeErr