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

add typing.ContextManager for 3.6+ only #1200

Closed
wants to merge 1 commit into from

Conversation

JelleZijlstra
Copy link
Member

This fixes the easier part of #655.

Would it make sense to add a generic typing.ContextManager that exists in any Python version?

This fixes the easier part of python#655.

Would it make sense to add a generic typing.ContextManager that exists in any Python version?
@gvanrossum
Copy link
Member

[Ahem, let me try that again.]

Would it make sense to add a generic typing.ContextManager that exists in any Python version?

Maybe, but it'll take a long time until everyone has it (esp. Python 3.5 users). I do think there's some room for improvement, esp. since the stdlib name is apparently AbstractContextManager. But let's merge this PR without waiting for that.

@gvanrossum
Copy link
Member

Don't merge yet, there may be a problem with this and our internal codebase.

@gvanrossum
Copy link
Member

Ironically the issues I am seeing are due to Python 2 code importing ContextLib (inside if MYPY). Let me see what I can do about it.

@gvanrossum
Copy link
Member

Sorry, I'm still waiting for a resolution on our end. This affects a fair amount of code.

@JelleZijlstra
Copy link
Member Author

If it's easier to move things forward, I'd be happy to keep contextlib.ContextManager in typeshed for now, although we should eventually remove it.

I imagine it's going to be helpful for use cases like yours if typing.ContextManager existed for Python < 3.6, so it could be used as an ABC. I'll propose that on the typing tracker.

@gvanrossum
Copy link
Member

OK, let's close this and keep typing.ContextManager in all versions, per python/typing#422.

@gvanrossum gvanrossum closed this May 3, 2017
@JelleZijlstra
Copy link
Member Author

We'll still need some changes here since currently there is no ContextManager in typing.pyi. I'll reopen this and make the appropriate changes once the typing PR is resolved.

@gvanrossum
Copy link
Member

Oh wait, you're right. This PR removes it from contextlib. We may still want that but first we want to add it to typing, so I can switch our usages to the latter.

FWIW the usages seem to be of the form

if MYPY:
    from contextlib import ContextManager
.
.
.
def foo(a):
    # type: (...) -> ContextManager[...]
    ...

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

2 participants