Skip to content

Commit c7851c0

Browse files
Prompt_toolkit 3.0: type annotations and asyncio natively.
This is a rewrite that starts taking advantage of Python 3 functionality. - It uses native asyncio coroutines and async generators everywhere. - We have type annotations in most of the code. - Python 2 support has been dropped (usage of six has been removed). - Use of ContextVars for keeping track of the currently running application.
1 parent eee625b commit c7851c0

File tree

268 files changed

+5928
-6923
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

268 files changed

+5928
-6923
lines changed

.travis.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,23 @@ matrix:
88
dist: xenial
99
sudo: required
1010
- python: 3.6
11-
- python: 3.5
12-
- python: 3.4
13-
- python: 2.7
14-
- python: 2.6
15-
- python: nightly
16-
- python: pypy
17-
- python: pypy3
1811

1912
install:
20-
- pip install . pytest coverage codecov flake8
21-
- if [ "$TRAVIS_PYTHON_VERSION" != "2.6" ]; then pip install isort; fi
13+
- pip install . pytest coverage codecov flake8 mypy
14+
- pip install isort
2215
- pip list
2316

2417
script:
2518
- echo "$TRAVIS_PYTHON_VERSION"
26-
- if [ "$TRAVIS_PYTHON_VERSION" != "2.6" ]; then flake8 prompt_toolkit; fi
19+
- flake8 prompt_toolkit
2720
- coverage run -m pytest
2821

22+
# Run type checker
23+
- mypy prompt_toolkit --ignore-missing-imports --platform win32 | grep -v 'already defined' | true
24+
2925
# Check wheather the imports were sorted correctly.
3026
# When this fails, please run ./tools/sort-imports.sh
31-
- if [ "$TRAVIS_PYTHON_VERSION" != "2.6" ]; then isort -c -m 3 -tc -rc prompt_toolkit; fi
27+
- isort -c -m 3 -tc -rc prompt_toolkit
3228

3329
after_success:
3430
- codecov

CHANGELOG

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
CHANGELOG
22
=========
33

4+
3.x.x
5+
-----------------
6+
7+
New features:
8+
- (almost) 100% type annotated.
9+
- Native asyncio instead of custom event loops.
10+
11+
Breaking changes:
12+
- Python 2 support has been dropped. Minimal Python version is now 3.6,
13+
although 3.7 is preferred (because of ContextVars).
14+
- Native asyncio, so some async code becomes slightly different.
15+
- The active `Application` became a contextvar. Which means that it should be
16+
propagated correctly to the code that requires it. However, random other
17+
threads or coroutines won't be able to know what the current application is.
18+
- The dialog shortcuts API changed. All dialog functions now return an
19+
`Application`. You still have to call either `run()` or `run_async` on the
20+
`Application` object.
21+
- The way inputhooks work is changed.
22+
- `patch_stdout` now requires an `Application` as input.
23+
24+
425
2.0.9: 2019-02-19
526
-----------------
627

README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ applications in Python.*
1111
Read the `documentation on readthedocs
1212
<http://python-prompt-toolkit.readthedocs.io/en/stable/>`_.
1313

14-
NOTICE: prompt_toolkit 2.0
14+
NOTICE: prompt_toolkit 3.0
1515
**************************
1616

17-
Please notice that this is prompt_toolkit 2.0. It is incompatible with the 1.0
18-
branch, but much better in many regards. Many applications are still using
19-
prompt_toolkit 1.0, but upgrading is strongly recommended. Feel free to open a
20-
new issue if you don't manage to upgrade to prompt_toolkit 2.0.
17+
Please notice that this branch is the prompt_toolkit 3.0 branch. For most
18+
users, it should be compatible with prompt_toolkit 2.0, but it requires at
19+
least Python 3.6. On the plus side, prompt_toolkit 3.0 is completly type
20+
annotated and uses asyncio natively.
2121

2222

2323
Ptpython

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
# built documents.
5252
#
5353
# The short X.Y version.
54-
version = '2.0.9'
54+
version = '3.0.0'
5555
# The full version, including alpha/beta/rc tags.
56-
release = '2.0.9'
56+
release = '3.0.0'
5757

5858
# The language for content autogenerated by Sphinx. Refer to documentation
5959
# for a list of supported languages.

examples/dialogs/button_dialog.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
"""
33
Example of button dialog window.
44
"""
5-
from __future__ import unicode_literals
6-
75
from prompt_toolkit.shortcuts import button_dialog
86

97

@@ -16,7 +14,7 @@ def main():
1614
('No', False),
1715
('Maybe...', None),
1816
],
19-
)
17+
).run()
2018

2119
print('Result = {}'.format(result))
2220

examples/dialogs/input_dialog.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
"""
33
Example of an input box dialog.
44
"""
5-
from __future__ import unicode_literals
6-
75
from prompt_toolkit.shortcuts import input_dialog
86

97

108
def main():
119
result = input_dialog(
1210
title='Input dialog example',
13-
text='Please type your name:')
11+
text='Please type your name:').run()
1412

1513
print('Result = {}'.format(result))
1614

examples/dialogs/messagebox.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
"""
33
Example of a message box window.
44
"""
5-
from __future__ import unicode_literals
6-
75
from prompt_toolkit.shortcuts import message_dialog
86

97

108
def main():
119
message_dialog(
1210
title='Example dialog window',
13-
text='Do you want to continue?\nPress ENTER to quit.')
11+
text='Do you want to continue?\nPress ENTER to quit.').run()
1412

1513

1614
if __name__ == '__main__':

examples/dialogs/password_dialog.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
"""
33
Example of an password input dialog.
44
"""
5-
from __future__ import unicode_literals
6-
75
from prompt_toolkit.shortcuts import input_dialog
86

97

108
def main():
119
result = input_dialog(
1210
title='Password dialog example',
1311
text='Please type your password:',
14-
password=True)
12+
password=True).run()
1513

1614
print('Result = {}'.format(result))
1715

examples/dialogs/progress_dialog.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
"""
33
Example of a progress bar dialog.
44
"""
5-
from __future__ import unicode_literals
6-
75
import os
86
import time
97

@@ -34,15 +32,14 @@ def worker(set_percentage, log_text):
3432
# Show 100% for a second, before quitting.
3533
set_percentage(100)
3634
time.sleep(1)
37-
return
3835

3936

4037
def main():
4138
progress_dialog(
4239
title='Progress dialog example',
4340
text='As an examples, we walk through the filesystem and print '
4441
'all directories',
45-
run_callback=worker)
42+
run_callback=worker).run()
4643

4744

4845
if __name__ == '__main__':

examples/dialogs/radio_dialog.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
"""
33
Example of a radio list box dialog.
44
"""
5-
from __future__ import unicode_literals
6-
75
from prompt_toolkit.formatted_text import HTML
86
from prompt_toolkit.shortcuts import radiolist_dialog
97

@@ -17,7 +15,7 @@ def main():
1715
('orange', 'Orange'),
1816
],
1917
title='Radiolist dialog example',
20-
text='Please select a color:')
18+
text='Please select a color:').run()
2119

2220
print('Result = {}'.format(result))
2321

@@ -30,7 +28,7 @@ def main():
3028
('orange', HTML('<style bg="orange" fg="white">Orange</style>')),
3129
],
3230
title=HTML('Radiolist dialog example <reverse>with colors</reverse>'),
33-
text='Please select a color:')
31+
text='Please select a color:').run()
3432

3533
print('Result = {}'.format(result))
3634

0 commit comments

Comments
 (0)