Skip to content

Commit 59c0987

Browse files
Michael0x2ailevkivskyi
authored andcommitted
Add typing extensions (#443)
This pull request adds a 'typing_exensions' subproject to 'typing'. The 'typing_extensions' module backports any new additions to 'typing' for Python 3.5+ users who are using older versions of 'typing' that were bundled with their standard library (and so can't update to the latest versions). As well, it will contain new experimental features than could eventually end up in 'typing'. See #435 for motivation and additional context.
1 parent 2b6932a commit 59c0987

9 files changed

+1751
-4
lines changed

.travis.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ language: python
33
python:
44
- "nightly"
55
- "3.7-dev"
6-
- "3.6"
7-
- "3.5"
6+
- "3.6.1"
7+
- "3.6.0"
8+
- "3.5.3"
9+
- "3.5.2"
10+
- "3.5.1"
11+
- "3.5.0"
812
- "3.4"
913
- "3.3"
1014
- "2.7"
@@ -14,5 +18,8 @@ install:
1418

1519
script:
1620
- export PYTHONPATH=`python -c "import sys; print('python2' if sys.version.startswith('2') else 'src')"`; py.test $PYTHONPATH
21+
- if [[ $TRAVIS_PYTHON_VERSION < '3.5' ]]; then python setup.py install; fi
22+
- export PYTHONPATH=`python -c "import sys; print('typing_extensions/src_py2' if sys.version.startswith('2') else 'typing_extensions/src_py3')"`;
23+
py.test $PYTHONPATH;
1724
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then flake8; fi
18-
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then flake8 --config=.flake8-tests src/test_typing.py python2/test_typing.py; fi
25+
- 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

test-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ flake8-pyi; python_version >= '3.6'
44
pytest>=2.8; python_version >= '3.3'
55
pytest-xdist>=1.13; python_version >= '3.3'
66
pytest-cov>=2.4.0; python_version >= '3.3'
7+
typing>=3.6.1; python_version <= '3.4'

tox.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ exclude =
2222
# tests have more relaxed formatting rules
2323
# and its own specific config in .flake8-tests
2424
python2/test_typing.py,
25-
src/test_typing.py
25+
src/test_typing.py,
26+
typing_extensions/src_py2/test_typing_extensions.py,
27+
typing_extensions/src_py3/test_typing_extensions.py,

typing_extensions/README.rst

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
=================
2+
Typing Extensions
3+
=================
4+
5+
.. image:: https://badges.gitter.im/python/typing.svg
6+
:alt: Chat at https://gitter.im/python/typing
7+
:target: https://gitter.im/python/typing?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
8+
9+
Overview
10+
========
11+
12+
The ``typing`` module was added to the standard library in Python 3.5 on
13+
a provisional basis and will no longer be provisional in Python 3.7. However,
14+
this means users of Python 3.5 - 3.6 who are unable to upgrade will not be
15+
able to take advantage of new types added to the ``typing`` module, such as
16+
``typing.Text`` or ``typing.Coroutine``.
17+
18+
The ``typing_extensions`` module contains both backports of these changes
19+
as well as experimental types that will eventually be added to the ``typing``
20+
module.
21+
22+
Users of other Python versions should continue to install and use
23+
use the ``typing`` module from PyPi instead of using this one unless
24+
specifically writing code that must be compatible with multiple Python
25+
versions or requires experimental types.
26+
27+
Included items
28+
==============
29+
30+
This module currently contains the following:
31+
32+
All Python versions:
33+
--------------------
34+
35+
- ``ClassVar``
36+
- ``ContextManager``
37+
- ``Counter``
38+
- ``DefaultDict``
39+
- ``Deque``
40+
- ``NewType``
41+
- ``NoReturn``
42+
- ``overload`` (note that older versions of ``typing`` only let you use ``overload`` in stubs)
43+
- ``Text``
44+
- ``Type``
45+
- ``TYPE_CHECKING``
46+
47+
Python 3.3+ only:
48+
-----------------
49+
50+
- ``ChainMap``
51+
52+
Python 3.5+ only:
53+
-----------------
54+
55+
- ``AsyncIterable``
56+
- ``AsyncIterator``
57+
- ``AsyncContextManager``
58+
- ``Awaitable``
59+
- ``Coroutine``
60+
61+
Python 3.6+ only:
62+
-----------------
63+
64+
- ``AsyncGenerator``
65+
66+
Other Notes and Limitations
67+
===========================
68+
69+
There are a few types whose interface was modified between different
70+
versions of typing. For example, ``typing.Sequence`` was modified to
71+
subclass ``typing.Reversible`` as of Python 3.5.3.
72+
73+
These changes are _not_ backported to prevent subtle compatibility
74+
issues when mixing the differing implementations of modified classes.
75+
76+
Running tests
77+
=============
78+
79+
To run tests, navigate into the appropriate source directory and run
80+
``test_typing_extensions.py``. You will also need to install the latest
81+
version of ``typing`` if you are using a version of Python that does not
82+
include ``typing`` as a part of the standard library.
83+

typing_extensions/setup.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
import sys
5+
from distutils.core import setup
6+
7+
if sys.version_info < (2, 7, 0) or (3, 0, 0) <= sys.version_info < (3, 3, 0):
8+
sys.stderr.write('ERROR: You need Python 2.7 or 3.3+ '
9+
'to install the typing package.\n')
10+
exit(1)
11+
12+
version = '3.6.1'
13+
description = 'Backported and Experimental Type Hints for Python 3.5+'
14+
long_description = '''\
15+
Typing Extensions -- Backported and Experimental Type Hints for Python
16+
17+
The ``typing`` module was added to the standard library in Python 3.5 on
18+
a provisional basis and will no longer be provisional in Python 3.7. However,
19+
this means users of Python 3.5 - 3.6 who are unable to upgrade will not be
20+
able to take advantage of new types added to the ``typing`` module, such as
21+
``typing.Text`` or ``typing.Coroutine``.
22+
23+
The ``typing_extensions`` module contains both backports of these changes
24+
as well as experimental types that will eventually be added to the ``typing``
25+
module.
26+
27+
Users of other Python versions should continue to install and use
28+
use the ``typing`` module from PyPi instead of using this one unless
29+
specifically writing code that must be compatible with multiple Python
30+
versions or requires experimental types.
31+
'''
32+
33+
classifiers = [
34+
'Development Status :: 3 - Alpha',
35+
'Environment :: Console',
36+
'Intended Audience :: Developers',
37+
'License :: OSI Approved :: Python Software Foundation License',
38+
'Operating System :: OS Independent',
39+
'Programming Language :: Python :: 2.7',
40+
'Programming Language :: Python :: 3.3',
41+
'Programming Language :: Python :: 3.4',
42+
'Programming Language :: Python :: 3.5',
43+
'Programming Language :: Python :: 3.6',
44+
'Topic :: Software Development',
45+
]
46+
47+
if sys.version_info.major == 2:
48+
package_dir = 'src_py2'
49+
elif sys.version_info.major == 3:
50+
package_dir = 'src_py3'
51+
else:
52+
raise AssertionError()
53+
54+
install_requires = []
55+
if sys.version_info < (3, 5):
56+
install_requires.append('typing >= 3.6.1')
57+
58+
setup(name='typing_extensions',
59+
version=version,
60+
description=description,
61+
long_description=long_description,
62+
author='Guido van Rossum, Jukka Lehtosalo, Lukasz Langa, Michael Lee',
63+
author_email='[email protected]',
64+
url='https://github.com/python/typing',
65+
license='PSF',
66+
keywords='typing function annotations type hints hinting checking '
67+
'checker typehints typehinting typechecking backport',
68+
package_dir={'': package_dir},
69+
py_modules=['typing_extensions'],
70+
classifiers=classifiers,
71+
install_requires=install_requires)

0 commit comments

Comments
 (0)