为什么 AbstractSet 不包含并集和交集?

Why does AbstractSet not include union and intersection?

是否有将 unionintersectionabc.Set 的定义方法中排除并因此从 typing.AbstractSet 中排除的书面原因?结果,我经常不得不在我希望能够使用 AbstractSet 的地方使用 Union[Set,FrozenSet]。考虑到 docs 建议对参数类型注释优先考虑 AbstractSet,这尤其令人费解。

权威来源

PEP 3119 定义抽象基 类。

总体设计目标是 "the ABCs define a minimal set of methods that establish the characteristic behavior of the type. Code that discriminates objects based on their ABC type can trust that those methods will always be present."

最小abc.SetAPI的具体原理只是顺便提一下,"the issubset and issuperset methods found on the set type in Python 2 are not supported, as these are mostly just aliases for __le__ and __ge__","this ABC does not provide the named methods present on the built-in concrete set type that perform (almost) the same operations."

collections.abc.Set只包括那些操作的运算符形式,|&。否则,接口将不会覆盖 dict.keysdict.items 返回的类集合对象,它们没有 unionintersection 方法。