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 example:
{} in {1:'a', 'b':2] <-- TypeError because of hashability set() in {1, 2, 'a', 'b'} <-- ditto
Right. Also, the members are not dicts or sets, respectively.
More precisely, none of the keys are an empty set.
[] in ['a', 'b', 1, 2] <-- False
The members are not lists.
'' in 'a1b2' <-- True
This is because "in" isn't measuring a setlike membership (I mean here, "subset"). It is looking for a substring. Compare:
>>> 'abc' in 'abcdef' True >>> 'abc' in 'abxcdef' False
So str is not a set, because of its sequential nature.
SomeFlag.nothing in SomeFlag.something <-- ???
I would expect "true", myself.
I'm not so sure. A flag could be a member, but could a set of flags?
Personally, I have never had a use for '' in 'some string' being True, [...] So, does Flag adhere to set theory, or is just happenstance that some operators work the same for both groups?
I would expect flags to be like sets. I've always thought of them that way - independent presence/absence of things. They're not sequenced. (If they're packed into ints there's some sequencing in the storage behind the scenes, but that isn't part of my model the rest of the time.)
Can we have `SomeFlag.nothing in SomeFlag.something` be `False`, or would that be too surprising?
I'd be surprised by this. I would rather a clean "subset" notion here.
I was going to digress about "<" vs "in". For sets, "<" means subset and "in" means "element in set". That isn't exactly parallel to flags. What if "SomeFlag.nothing < SomeFlag.something" meant a subset test? Would we need "in" at all? Or is "<" out of the picture because FLags, or at least IntFlags, might do numeric-like stuff with "<"?
Actually, '<' means _proper_ subset (not ==), '<=' means subset (possibly ==).