-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-118660: Add second type parameter to (Async)ContextManager #118681
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
Conversation
cc @Daverball |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would maybe put a little bit more emphasis on the new type parameter being optional. While it defaulting to bool | None
implies that, it's maybe a little bit too subtle for user-facing documentation, especially for a new feature in 3.13.
We could also consider changing the notation from Generic[T_co, ExitT_co]
to Generic[T_co, ExitT_co = bool | None]
, so its behavior can be inferred just from this header, similar to function signatures, even if that is not valid syntax, it's similar to PEP-695 notation, while retaining the implicit reference to Generic
within the typing module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered that syntax with Generic but didn't use it here because it's a SyntaxError. Switching to PEP 695 syntax might be nice but I think it causes problems with Sphinx. In any case, this is something we can adjust after the beta.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we have to use an old version of Sphinx to keep Linux redistributors happy, and old versions of Sphinx don't know about PEP-695 syntax so they do weird things with the syntax highlighting
Misc/NEWS.d/next/Library/2024-05-06-18-13-02.gh-issue-118660.n01Vb7.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Alex Waygood <[email protected]>
Misc/NEWS.d/next/Library/2024-05-06-18-13-02.gh-issue-118660.n01Vb7.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Alex Waygood <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Some "optional" inline suggestions below that might alleviate @Daverball's concerns a bit:
Misc/NEWS.d/next/Library/2024-05-06-18-13-02.gh-issue-118660.n01Vb7.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Alex Waygood <[email protected]>
This is in response to: python/cpython#118681
…ython#118681) Co-authored-by: Alex Waygood <[email protected]>
) This is in response to: python/cpython#118681
typing.ContextManager
andtyping.AbstractContextManager
#118660