8000 Proposal: ContextManager interface · Issue #274 · python/typing · GitHub
[go: up one dir, main page]

Skip to content

Proposal: ContextManager interface #274

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

Closed
drewhaven opened this issue Aug 31, 2016 · 2 comments
Closed

Proposal: ContextManager interface #274

drewhaven opened this issue Aug 31, 2016 · 2 comments

Comments

@drewhaven
Copy link

Because context managers are a language feature (for use in with blocks), typing should expose an interface class for them like it does with Dict, List, etc.

The typeshed for contextlib defines an interface for a ContextManager because it needs it in the return type for contextlib.contextmanager, but it seems like the kind of thing that should be in typing, not in a random stub.

@gvanrossum
Copy link
Member

Yeah, and in Python 3.6 there's contextlib.AbstractContextManager in the
stdlib, from which typing.ContextManager inherits if it exists, and
otherwise typing doesn't define ContextManager at all. I guess what we
should do is, if contextlib.AbstractContextManager doesn't exist (i.e.
3.5 or earlier), typing.ContextManager should just fake one.

@JelleZijlstra
Copy link
Member

I was just going to propose what Guido is suggesting above (based on discussion in python/typeshed#1200). Since this issue has already been open for months with no objection to the idea, I'll send a PR instead.

JelleZijlstra added a commit to JelleZijlstra/typing that referenced this issue May 3, 2017
So that there is a way to type hint for a context manager even on
language versions before 3.6.

This is just copied from contextlib.AbstractContextManager in 3.6.

Fixes python#274
JelleZijlstra added a commit to JelleZijlstra/typing that referenced this issue May 3, 2017
So that there is a way to type hint for a context manager even on
language versions before 3.6.

This is just copied from contextlib.AbstractContextManager in 3.6.

Fixes python#274
gvanrossum pushed a commit that referenced this issue May 6, 2017
So that there is a way to type hint for a context manager even on
language versions before 3.6.

This is just copied from contextlib.AbstractContextManager in 3.6.

Fixes #274
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

No branches or pull requests

3 participants
0