PEP 724: Stricter Type Guards

I thought I’d try and assess how much of a problem the backward incompatibility is in practice. As stroxler mentions, mypy_primer is limited in its ability to assess whether switching to PEP 724 creates soundness holes. With that in mind, I went through the first ten projects in Code search results · GitHub

(bonus, since it was mentioned in this thread)

Summary:

I was hoping for clarity, but I didn’t really get it. I did find real-world type guard functions where 724 semantics introduces potential for unsoundness where there previously wasn’t any. At the same time, none of these cases seem like particularly bad breakage — they weren’t public APIs and from what I could tell didn’t seem to be used in ways that the holes opened really mattered (although there’s survivorship bias when looking for buggy code).

4 Likes