You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add additional optional type parameter to typing.ContextManager and typing.AbstractContextManager #118660
As part of python/typeshed#11048contextlib.AbstractContextManager and contextlib.AbstractAsyncContextManager received an additional optional type parameter for the return value of __exit__ in order to have greater control over code-flow analysis in type checkers with things like ExitStack.
The contextlibABCs don't require any changes, since they accept an arbitrary number of arguments at runtime, but the aliases that live in typing are a different story. These will reject the additional parameter at runtime, throwing an exception.
@JelleZijlstra Added support for type var defaults for typing._SpecialGenericAlias in #118648, we could leverage that work to add the new optional parameter to the typing aliases, so they can support the same number of type parameters as their contextlib counterparts.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Activity
pythongh-118660: Add second type parameter to (Async)ContextManager
gh-118660: Add second type parameter to (Async)ContextManager (#118681)
pythongh-118660: Add second type parameter to (Async)ContextManager (p…