I’ve written a first draft of a new chapter for the typing spec that focuses on type checker behaviors for context managers — whether or not they suppress exceptions based on the return type of the __exit__
method.
This behavior was first proposed in this mypy issue, and all major type checkers have adopted this convention since then. This is simply an attempt to codify the rules that were established five years ago.
If you are interested in reviewing the draft, you can find it in this PR.
This is a short spec (half a page total), and I don’t think the proposal will be controversial. Please review for clarity and completeness.
I’m proposing to put this in its own chapter titled “Exceptions” because it didn’t seem to fit in any other existing chapters. Alternatively, we could name the chapter “Context Managers”. I’m open to suggestions here.