Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does AbstractSet not include union and intersection?

Is there a documented reason for excluding union and intersection from the defining methods of abc.Set and thereby from typing.AbstractSet? As a result, I often have to use Union[Set,FrozenSet] where I expected to be able to use AbstractSet. This is particularly puzzling given that the docs suggest giving preference to AbstractSet for argument type annotations.

like image 228
Alan Avatar asked Nov 06 '22 07:11

Alan


1 Answers

Authoratative Source

PEP 3119 defines the abstract bases classes.

The overall design goal was for "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."

The specific rationale for the minimal abc.Set API is mentioned only in passing, "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__", and "this ABC does not provide the named methods present on the built-in concrete set type that perform (almost) the same operations."

like image 159
Raymond Hettinger Avatar answered Nov 14 '22 21:11

Raymond Hettinger