Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add additional optional type parameter totyping.ContextManager andtyping.AbstractContextManager #118660

Closed
Labels
@Daverball

Description

@Daverball

Feature or enhancement

Proposal:

As part ofpython/typeshed#11048contextlib.AbstractContextManager andcontextlib.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 likeExitStack.

ThecontextlibABCs don't require any changes, since they accept an arbitrary number of arguments at runtime, but the aliases that live intyping are a different story. These will reject the additional parameter at runtime, throwing an exception.

@JelleZijlstra Added support for type var defaults fortyping._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 theircontextlib counterparts.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/add-an-else-clause-to-with-statements-to-detect-early-termination/38031

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp