-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
Had this thought while reviewing #2890: Currently in a number of places we accept either a single item (say a string) or a tuple/list of containing items of the same type. Using concrete types here originally was motivated because we had documented as Iterable in a few places - iterables allow generators, which might be inifininte and will also be consumed.
Anyway, time has passed and I've learned a bit more. In most of those cases, we just want to make sure that we get a finite number of items - this is covered by Collection. If in addition, we need item access or loop over the items in reversed order, we can use Sequence.
So I'd suggest to replace the current types.SLT with two new types for
Union[T, Collection[T]]andUnion[T, Sequence[T]]
and adjusting the documentation accordingly. I imagine the transition not be to be hard: We replace SLT with Union[T, Collection[T]] everywhere. If we need it to be Union[T, Sequence[T]] somewhere, then mypy will hopefully complain :)
This change would be non-breaking, so not necessarily urgent for v14.