Skip to content

Add typing.ClassVar (fixes #888) #889

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

Merged
merged 1 commit into from
Jan 30, 2017
Merged

Conversation

miedzinski
Copy link
Contributor

@miedzinski miedzinski commented Jan 28, 2017

As title says. Resolves #888.

@gvanrossum
Copy link
Member

To resolve #888, this should also be added to stdlib/2/typing.pyi.

@miedzinski
Copy link
Contributor Author

Looks like adding import sys to stdlib/2/typing.pyi causes

stdlib/2/types.pyi:16: error: Cannot determine type of 'long'

Should I ignore it or remove version check from stdlib/2? Is it actually needed there? Python docs mention it was added in 3.5.3. I think it could be clarified in CONTRIBUTING file.

@gvanrossum
Copy link
Member

gvanrossum commented Jan 30, 2017 via email

@miedzinski
Copy link
Contributor Author

That makes more sense. :) There are comments in that stub that convinced me that ClassVar shouldn't be defined on Python <3.5.

# TODO: Several types should only be defined if sys.python_version >= (3, 5):
# Awaitable, AsyncIterator, AsyncIterable, Coroutine, Collection, ContextManager.
# See https: //github.com/python/typeshed/issues/655 for why this is not easy.
# TODO: ContextManager (only if contextlib.AbstractContextManager exists)

https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#stub-versioning doesn't help either.

@gvanrossum gvanrossum merged commit d486e2a into python:master Jan 30, 2017
@gvanrossum
Copy link
Member

That comment refers to types that are defined in the language or in other parts of the stdlib, and only appear in newer Python versions. But ClassVar is unconditionally defined in typing.py, so it will work whenever a new enough typing.py is present. (True, it won't exist in the stdlib version for Python 3.5.0--3.5.2, but that's where that section in CONTRIBUTING.md applies -- it does exist in the stdlib for 3.5.3.)

Anyway, this still requires changes to mypy as well -- we're tracking that in python/mypy#2771.

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.

2 participants