PEP 742: Narrowing types with TypeIs

I can agree with you on that, I would personally prefer TypeNarrower or Narrowed over TypeIs, since there is some ambiguity about type identity vs. A is a int, as in, it is some int (including subclasses), not THE int.

As for your 2nd point, If we were going to add a third type-guard-like construct I would prefer it to be this, which also guarantees safety:

With TypeIs vs ForceTypeIs it becomes just as easy to accidentally use one over the other as it would be to write an incorrect type narrower in the first place, so I don’t think it’s a big enough win personally.

2 Likes