Skip to content

Add typing extensions #443

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 23 commits into from
Jul 20, 2017
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
591f737
Add typing_extensions subfolder
Michael0x2a Jun 27, 2017
ed2e142
Remove unnecessary gitignore
Michael0x2a Jun 27, 2017
eb1e5d7
Fix flake8 errors; make travis test typing_extensions
Michael0x2a Jun 27, 2017
bded015
Fix tests and lint errors; make run_tests.py Python 3 only
Michael0x2a Jun 27, 2017
449a339
Fix typo in .travis.yml
Michael0x2a Jun 27, 2017
baa6ba7
Try making travis run on each minor version
Michael0x2a Jun 27, 2017
5f55de2
Experiment with removing sys.argv hacks
Michael0x2a Jun 27, 2017
d9d10a5
Correctly use sys.version_info
Michael0x2a Jun 27, 2017
2746fae
Cleanup lingering test changes
Michael0x2a Jun 27, 2017
292deb9
Address parts of code review
Michael0x2a Jul 7, 2017
11e98ee
Fix tests; tweak setup.py text
Michael0x2a Jul 7, 2017
9cc6236
Add missing definitions in Python 2 tests
Michael0x2a Jul 7, 2017
ea77bf9
A little closer
Michael0x2a Jul 7, 2017
5e243ed
Whoops, forgot old-style classes were a thing
Michael0x2a Jul 7, 2017
eac513c
Add check to see if cls.__bases__ is erased
Michael0x2a Jul 7, 2017
ea52ad8
Fix import
Michael0x2a Jul 7, 2017
dd9f31c
Consolidate and document version checks in py3 tests
Michael0x2a Jul 7, 2017
31de561
Test version check pin
Michael0x2a Jul 7, 2017
67a20cb
Special-case quirk with AsyncIterator
Michael0x2a Jul 7, 2017
6987247
Convert readme to RST format; adjust text
Michael0x2a Jul 7, 2017
eab214c
Remove Collections backport
Michael0x2a Jul 8, 2017
11c0fcf
Incorporate speed improvements for typing
Michael0x2a Jul 17, 2017
76cc99d
Respond to 2nd review feedback
Michael0x2a Jul 20, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -3,8 +3,12 @@ language: python
python:
- "nightly"
- "3.7-dev"
- "3.6"
- "3.5"
- "3.6.1"
- "3.6.0"
- "3.5.3"
- "3.5.2"
- "3.5.1"
- "3.5.0"
- "3.4"
- "3.3"
- "2.7"
@@ -14,5 +18,8 @@ install:

script:
- export PYTHONPATH=`python -c "import sys; print('python2' if sys.version.startswith('2') else 'src')"`; py.test $PYTHONPATH
- if [[ $TRAVIS_PYTHON_VERSION < '3.5' ]]; then python setup.py install; fi
- export PYTHONPATH=`python -c "import sys; print('typing_extensions/src_py2' if sys.version.startswith('2') else 'typing_extensions/src_py3')"`;
py.test $PYTHONPATH;
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then flake8; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then flake8 --config=.flake8-tests src/test_typing.py python2/test_typing.py; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then flake8 --config=.flake8-tests src/test_typing.py python2/test_typing.py typing_extensions/src_py2/test_typing_extensions.py typing_extensions/src_py3/test_typing_extensions.py; fi
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -4,3 +4,4 @@ flake8-pyi; python_version >= '3.6'
pytest>=2.8; python_version >= '3.3'
pytest-xdist>=1.13; python_version >= '3.3'
pytest-cov>=2.4.0; python_version >= '3.3'
typing>=3.6.1; python_version <= '3.4'
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -22,4 +22,6 @@ exclude =
# tests have more relaxed formatting rules
# and its own specific config in .flake8-tests
python2/test_typing.py,
src/test_typing.py
src/test_typing.py,
typing_extensions/src_py2/test_typing_extensions.py,
typing_extensions/src_py3/test_typing_extensions.py,
83 changes: 83 additions & 0 deletions typing_extensions/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
=================
Typing Extensions
=================

.. image:: https://badges.gitter.im/python/typing.svg
:alt: Chat at https://gitter.im/python/typing
:target: https://gitter.im/python/typing?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge

Overview
========

The ``typing`` module was added to the standard library in Python 3.5 on
a provisional basis and will no longer be provisional in Python 3.7. However,
this means users of Python 3.5 - 3.6 who are unable to upgrade will not be
able to take advantage of new types added to the ``typing`` module, such as
``typing.Text`` or ``typing.Coroutine``.

The ``typing_extensions`` module contains both backports of these changes
as well as experimental types that will eventually be added to the ``typing``
module.

Users of other Python versions should continue to install and use
use the ``typing`` module from PyPi instead of using this one unless
specifically writing code that must be compatible with multiple Python
versions or requires experimental types.

Included items
==============

This module currently contains the following:

All Python versions:
--------------------

- ``ClassVar``
- ``ContextManager``
- ``Counter``
- ``DefaultDict``
- ``Deque``
- ``NewType``
- ``NoReturn``
- ``overload`` (note that older versions of ``typing`` only let you use ``overload`` in stubs)
- ``Text``
- ``Type``
- ``TYPE_CHECKING``

Python 3.3+ only:
-----------------

- ``ChainMap``

Python 3.5+ only:
-----------------

- ``AsyncIterable``
- ``AsyncIterator``
- ``AsyncContextManager``
- ``Awaitable``
- ``Coroutine``

Python 3.6+ only:
-----------------

- ``AsyncGenerator``

Other Notes and Limitations
===========================

There are a few types whose interface was modified between different
versions of typing. For example, ``typing.Sequence`` was modified to
subclass ``typing.Reversible`` as of Python 3.5.3.

These changes are _not_ backported to prevent subtle compatibility
issues when mixing the differing implementations of modified classes.

Running tests
=============

To run tests, navigate into the appropriate source directory and run
``test_typing_extensions.py``. You will also need to install the latest
version of ``typing`` if you are using a version of Python that does not
include ``typing`` as a part of the standard library.

71 changes: 71 additions & 0 deletions typing_extensions/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python
# coding: utf-8

import sys
from distutils.core import setup

if sys.version_info < (2, 7, 0) or (3, 0, 0) <= sys.version_info < (3, 3, 0):
sys.stderr.write('ERROR: You need Python 2.7 or 3.3+ '
'to install the typing package.\n')
exit(1)

version = '3.6.1'
description = 'Backported and Experimental Type Hints for Python 3.5+'
long_description = '''\
Typing Extensions -- Backported and Experimental Type Hints for Python

The ``typing`` module was added to the standard library in Python 3.5 on
a provisional basis and will no longer be provisional in Python 3.7. However,
this means users of Python 3.5 - 3.6 who are unable to upgrade will not be
able to take advantage of new types added to the ``typing`` module, such as
``typing.Text`` or ``typing.Coroutine``.

The ``typing_extensions`` module contains both backports of these changes
as well as experimental types that will eventually be added to the ``typing``
module.

Users of other Python versions should continue to install and use
use the ``typing`` module from PyPi instead of using this one unless
specifically writing code that must be compatible with multiple Python
versions or requires experimental types.
'''

classifiers = [
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: Python Software Foundation License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Software Development',
]

if sys.version_info.major == 2:
package_dir = 'src_py2'
elif sys.version_info.major == 3:
package_dir = 'src_py3'
else:
raise AssertionError()

install_requires = []
if sys.version_info < (3, 5):
install_requires.append('typing >= 3.6.1')

setup(name='typing_extensions',
version=version,
description=description,
long_description=long_description,
author='Guido van Rossum, Jukka Lehtosalo, Lukasz Langa, Michael Lee',
author_email='[email protected]',
url='https://github.com/python/typing',
license='PSF',
keywords='typing function annotations type hints hinting checking '
'checker typehints typehinting typechecking backport',
package_dir={'': package_dir},
py_modules=['typing_extensions'],
classifiers=classifiers,
install_requires=install_requires)
Loading