I'm not sure what you mean by "Any swallows all errors" in the context of a `Sequence[Any]`.
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[0].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]`.
Best,
Rebecca
On Mon, Oct 19, 2020 at 1:48 PM Guido van Rossum
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 -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: rechen@google.com