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 <et...@stoneleaf.us> 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. >[] 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. >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 "<"? Cheers, Cameron Simpson <c...@cskk.id.au> _______________________________________________ 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 archived at https://mail.python.org/archives/list/python-dev@python.org/message/Y2D2CUBO3C76DFTQTFV2V4IN7WPS72HD/ Code of Conduct: http://python.org/psf/codeofconduct/