Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added typing spec chapter focused on exception behavior #1718

Merged
merged 3 commits into from Apr 22, 2024

Conversation

erictraut
Copy link
Collaborator

Added typing spec chapter focused on exception behavior — in particular, context managers and whether they suppress exceptions.

…ar, context managers and whether they suppress exceptions.
docs/spec/exceptions.rst Outdated Show resolved Hide resolved
@hauntsaninja
Copy link
Collaborator

I wonder if it's also worth having one sentence explaining why bool | None does not admit the possibility of exception suppression. E.g. in https://discuss.python.org/t/suppression-of-exceptions-within-context-managers-vs-variable-definitions/47256 I think OP was a little confused till linked to the mypy issue where Jelle proposed this heuristic.

@maxfischer2781
Copy link

I wonder if it's also worth having one sentence explaining why bool | None does not admit the possibility of exception suppression.

Yes please. Looking at this without knowing its motivation this is extremely confusing otherwise. Starting from the datamodel, one must assume that -> Literal[True, ...] is the important part no matter what the ... is. So -> bool and -> bool | None would behave the same as they both include the case of True.
Explaining that this rule prefers convenience (only the less common suppressing context managers need special handling) over strictness (the more common non-suppressing context managers need precise annotations) would make it clear that this is not an error but by design.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits.

docs/spec/exceptions.rst Outdated Show resolved Hide resolved
docs/spec/exceptions.rst Outdated Show resolved Hide resolved
@erictraut erictraut marked this pull request as ready for review April 22, 2024 20:46
@erictraut
Copy link
Collaborator Author

The TC has signed off on this change, so I'm proceeding to merge it.

@erictraut erictraut merged commit 2535760 into python:main Apr 22, 2024
5 checks passed
@erictraut erictraut deleted the exceptions_spec branch April 22, 2024 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants