Steven D'Aprano wrote:
    isinstance([], List[int])
    isinstance([], List[str])

How can a single value be an instance of two mutually incompatible types?

I don't think there's any contradiction there, because the
compatibility rules are different for static and runtime types.
Statically, when you assign something of type A to a variable
of type B, you're assering that *all* values of type A are
compatible with B. But at runtime, you're only asserting that
one *particular* value is compatible with B.

> It just seems
perverse to me to say that it is "meaningless" (in Mark's words) to ask whether

    isinstance(['a', 'b'], List[int])
    isinstance(123, List[str])

for example). If static type checking has any meaning at all, then the answers to those two surely have to be False.

I doubt whether Mark meant "separate" to imply "unrelated".
Static and runtime types are clearly related, although the
relationship is not one-to-one and involves complicated
overlaps.

To my mind, the question isn't whether tests like that are
meaningful -- clearly they are. The question is whether we
should attempt to support answering them at run time, given
that doing so in the general case requires unbounded amounts
of computation.

--
Greg

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to