
Jan. 5, 2021
7:36 p.m.
There was some discussion in this thread of type guards vs conditional casts. Given that Shantanu's point that a type guard is similar to an if-clause followed by cast makes sense at least to me, maybe it would make sense to add a section under "Rejected Ideas" for basically "add no features; use conditional casts"? (or the slightly stronger suggestion to have checkers allow name redefinition in casts.) That way the PEP could explain the rationale for why TypeGuard approach is better than what can be achieved by conditional casts. As far as I can tell, some of the features which were discussed like enforcing only strict narrowing, and narrowing both the positive and negative cases, have been dropped.