PEP 742: Narrowing types with TypeIs

The Typing Council has voted in favor of PEP 742 in its current form. All TC members support the TypeIs name. It has been a bit of a struggle to get here but we are now ready to recommend PEP 742 to the Steering Council, in preference of PEP 724.

(As you may remember, PEP 724 proposed to change the existing TypeGuard special form (introduced by PEP 647) to implement more desirable semantics for type guards, creating some edge cases where the semantics would change for existing code (causing type checkers to occasionally produce new errors). There was all round agreement that the new semantics are in most cases better, but a majority of the TC found the backward incompatibility in edge cases unacceptable. Therefore Jelle drafted PEP 742, which proposes a new name for the new semantics (without proposing to deprecate TypeGuard, as its different semantics are occasionally useful). There was considerable bikeshedding on the name of the new special form, but we ultimately landed and agreed on TypeIs. Details of the breaking edge cases are in PEP 724’s Backwards Compatibility section.)

20 Likes