I'm not sure what you mean by "Any swallows all errors" in the context of
If you access an element of a container annotated as Sequence[Any], then a type checker will let you do anything you want with that element (access a non-existent attribute, pass it to a method that expects a particular type, etc.).
Similarly, the difference between def swap(items: MutableSequence[Any], i: int, j: int): ... and _T1 = TypeVar("_T1") def swap(items: MutableSequence[_T1], i: int, j: int): ... is that in the body of `swap`, something like `items.nonexistent_attribute` will not be flagged as an error in the first case but will in the second. So, as I understand it, the argument for using `MutableSequence[_T1]` is that it behaves like a covariant flavor of `MutableSequence[object]`.
On Mon, Oct 19, 2020 at 1:48 PM Guido van Rossum firstname.lastname@example.org wrote:
I recall seeing various bug reports for mypy where people misunderstand type variables with an upper bound (or is that lower bound? :-) and use them where they should be using Unions. So I think it's useful to reject these.
OTOH I have at least a little sympathy for stub authors writing a bunch of stub functions, some of which take two arguments of type SomeT and a few of which take only one such -- it's annoying to have to define a union *and* a typevar and to remember which to use when. (Especially since there is also real danger in writing SomeUnion for two two arguments.)
-- --Guido van Rossum (python.org/~guido) Pronouns: he/him (why is my pronoun here?) _______________________________________________ Typing-sig mailing list -- email@example.com To unsubscribe send an email to firstname.lastname@example.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: email@example.com