[Python-ideas] add __contains__ into the "type" object

Chris Angelico rosuav at gmail.com
Thu Mar 2 08:50:46 EST 2017


On Fri, Mar 3, 2017 at 12:44 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> Compare to the OP's suggestion:
>
>     23 in int
>
> This doesn't even make sense unless you have been exposed to a very
> small subset of theoretical computer science which treats classes as
> sets and instances as elements of those sets. To everyone else,
> especially those with a background in "ordinary" OOP, it looks like
> nonsense.
>
> (Personally, I'm a bit dubious about conflating is-a and element-of
> operations in this way, it feels like a category mistake to me, but for
> the sake of the argument I'll accept it.)

I've seen languages in which types can be the RHO of 'is', so this
would look like:

23 is int

Obviously that depends on types not themselves being first-class
objects, but it makes a lot more sense than a containment check.

But I'm trying to think how frequently I do *any* type checking in
production code. It's not often. It doesn't need syntax.
isinstance(23, int) works fine.

ChrisA


More information about the Python-ideas mailing list