On Sun, Oct 13, 2019 at 07:15:09PM -0000, Steve Jorgensen wrote:
> …and that leaves only the suggestion that `type.__contains__(self,
> other)` could be a synonym for `isinstance(other, self)`.
We don't normally think of an instance as being an element contained by
its class. We wouldn't say that Nemo is *in* the type Fish, we say that
Nemo *is a* Fish, and we don't expect that iterating over Fish will
eventually yield Nemo.
In Python, we spell containment testing as `in` and `is-a` relationship
testing as `isinstance`. But types aren't containers and we surely don't
want
isinstance(float, collections.abc.Container)
to return True. Even when the class can be identified as equivalent to
its set of values, such as for numeric types, there are all sorts of
complexities that will only lead to confusion:
from numbers import Real
1.0 in Real # okay, unproblematic
2+3j in complex # also okay
1 in complex # mathematically true, but isinstance-wise false
float('INF') in Real # isinstance-wise true, but mathematically false.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/LQRGFLQPZRDWD3AN3KKUN6WRPDRSWXQ6/
Code of Conduct: http://python.org/psf/codeofconduct/