Skip to content

Commit be972ab

Browse files
Drop Python 3.6.
Now that prompt_toolkit itself dropped Python 3.6 support, we can drop Python 3.6 too.
1 parent 3f24501 commit be972ab

22 files changed

+169
-130
lines changed

ptpython/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from .repl import embed
24

35
__all__ = ["embed"]

ptpython/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Make `python -m ptpython` an alias for running `./ptpython`.
33
"""
4+
from __future__ import annotations
5+
46
from .entry_points.run_ptpython import run
57

68
run()

ptpython/completer.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import ast
24
import collections.abc as collections_abc
35
import inspect
@@ -44,8 +46,8 @@ class PythonCompleter(Completer):
4446

4547
def __init__(
4648
self,
47-
get_globals: Callable[[], Dict[str, Any]],
48-
get_locals: Callable[[], Dict[str, Any]],
49+
get_globals: Callable[[], dict[str, Any]],
50+
get_locals: Callable[[], dict[str, Any]],
4951
enable_dictionary_completion: Callable[[], bool],
5052
) -> None:
5153
super().__init__()
@@ -58,8 +60,8 @@ def __init__(
5860
self._jedi_completer = JediCompleter(get_globals, get_locals)
5961
self._dictionary_completer = DictionaryCompleter(get_globals, get_locals)
6062

61-
self._path_completer_cache: Optional[GrammarCompleter] = None
62-
self._path_completer_grammar_cache: Optional["_CompiledGrammar"] = None
63+
self._path_completer_cache: GrammarCompleter | None = None
64+
self._path_completer_grammar_cache: _CompiledGrammar | None = None
6365

6466
@property
6567
def _path_completer(self) -> GrammarCompleter:
@@ -74,7 +76,7 @@ def _path_completer(self) -> GrammarCompleter:
7476
return self._path_completer_cache
7577

7678
@property
77-
def _path_completer_grammar(self) -> "_CompiledGrammar":
79+
def _path_completer_grammar(self) -> _CompiledGrammar:
7880
"""
7981
Return the grammar for matching paths inside strings inside Python
8082
code.
@@ -85,7 +87,7 @@ def _path_completer_grammar(self) -> "_CompiledGrammar":
8587
self._path_completer_grammar_cache = self._create_path_completer_grammar()
8688
return self._path_completer_grammar_cache
8789

88-
def _create_path_completer_grammar(self) -> "_CompiledGrammar":
90+
def _create_path_completer_grammar(self) -> _CompiledGrammar:
8991
def unwrapper(text: str) -> str:
9092
return re.sub(r"\\(.)", r"\1", text)
9193

@@ -202,8 +204,8 @@ class JediCompleter(Completer):
202204

203205
def __init__(
204206
self,
205-
get_globals: Callable[[], Dict[str, Any]],
206-
get_locals: Callable[[], Dict[str, Any]],
207+
get_globals: Callable[[], dict[str, Any]],
208+
get_locals: Callable[[], dict[str, Any]],
207209
) -> None:
208210
super().__init__()
209211

@@ -241,7 +243,7 @@ def get_completions(
241243
# Jedi issue: "KeyError: u'a_lambda'."
242244
# https://github.com/jonathanslenders/ptpython/issues/89
243245
pass
244-
except IOError:
246+
except OSError:
245247
# Jedi issue: "IOError: No such file or directory."
246248
# https://github.com/jonathanslenders/ptpython/issues/71
247249
pass
@@ -302,8 +304,8 @@ class DictionaryCompleter(Completer):
302304

303305
def __init__(
304306
self,
305-
get_globals: Callable[[], Dict[str, Any]],
306-
get_locals: Callable[[], Dict[str, Any]],
307+
get_globals: Callable[[], dict[str, Any]],
308+
get_locals: Callable[[], dict[str, Any]],
307309
) -> None:
308310
super().__init__()
309311

@@ -385,7 +387,7 @@ def __init__(
385387
re.VERBOSE,
386388
)
387389

388-
def _lookup(self, expression: str, temp_locals: Dict[str, Any]) -> object:
390+
def _lookup(self, expression: str, temp_locals: dict[str, Any]) -> object:
389391
"""
390392
Do lookup of `object_var` in the context.
391393
`temp_locals` is a dictionary, used for the locals.
@@ -429,7 +431,7 @@ def _do_repr(self, obj: object) -> str:
429431
except BaseException:
430432
raise ReprFailedError
431433

432-
def eval_expression(self, document: Document, locals: Dict[str, Any]) -> object:
434+
def eval_expression(self, document: Document, locals: dict[str, Any]) -> object:
433435
"""
434436
Evaluate
435437
"""
@@ -444,7 +446,7 @@ def _get_expression_completions(
444446
self,
445447
document: Document,
446448
complete_event: CompleteEvent,
447-
temp_locals: Dict[str, Any],
449+
temp_locals: dict[str, Any],
448450
) -> Iterable[Completion]:
449451
"""
450452
Complete the [ or . operator after an object.
@@ -467,7 +469,7 @@ def _get_item_lookup_completions(
467469
self,
468470
document: Document,
469471
complete_event: CompleteEvent,
470-
temp_locals: Dict[str, Any],
472+
temp_locals: dict[str, Any],
471473
) -> Iterable[Completion]:
472474
"""
473475
Complete dictionary keys.
@@ -547,7 +549,7 @@ def _get_attribute_completions(
547549
self,
548550
document: Document,
549551
complete_event: CompleteEvent,
550-
temp_locals: Dict[str, Any],
552+
temp_locals: dict[str, Any],
551553
) -> Iterable[Completion]:
552554
"""
553555
Complete attribute names.
@@ -579,13 +581,13 @@ def get_suffix(name: str) -> str:
579581
suffix = get_suffix(name)
580582
yield Completion(name, -len(attr_name), display=name + suffix)
581583

582-
def _sort_attribute_names(self, names: List[str]) -> List[str]:
584+
def _sort_attribute_names(self, names: list[str]) -> list[str]:
583585
"""
584586
Sort attribute names alphabetically, but move the double underscore and
585587
underscore names to the end.
586588
"""
587589

588-
def sort_key(name: str) -> Tuple[int, str]:
590+
def sort_key(name: str) -> tuple[int, str]:
589591
if name.startswith("__"):
590592
return (2, name) # Double underscore comes latest.
591593
if name.startswith("_"):
@@ -650,7 +652,7 @@ class ReprFailedError(Exception):
650652

651653

652654
def _get_style_for_jedi_completion(
653-
jedi_completion: "jedi.api.classes.Completion",
655+
jedi_completion: jedi.api.classes.Completion,
654656
) -> str:
655657
"""
656658
Return completion style to use for this name.

ptpython/contrib/asyncssh_repl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
should make sure not to use Python 3-only syntax, because this
77
package should be installable in Python 2 as well!
88
"""
9+
from __future__ import annotations
10+
911
import asyncio
1012
from typing import Any, Optional, TextIO, cast
1113

@@ -29,7 +31,7 @@ class ReplSSHServerSession(asyncssh.SSHServerSession):
2931
"""
3032

3133
def __init__(
32-
self, get_globals: _GetNamespace, get_locals: Optional[_GetNamespace] = None
34+
self, get_globals: _GetNamespace, get_locals: _GetNamespace | None = None
3335
) -> None:
3436
self._chan: Any = None
3537

ptpython/entry_points/run_ptipython.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env python
2+
from __future__ import annotations
3+
24
import os
35
import sys
46

@@ -58,7 +60,7 @@ def run(user_ns=None):
5860
code = compile(f.read(), path, "exec")
5961
exec(code, user_ns, user_ns)
6062
else:
61-
print("File not found: {}\n\n".format(path))
63+
print(f"File not found: {path}\n\n")
6264
sys.exit(1)
6365

6466
# Apply config file

ptpython/entry_points/run_ptpython.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
PTPYTHON_CONFIG_HOME: a configuration directory to use
2222
PYTHONSTARTUP: file executed on interactive startup (no default)
2323
"""
24+
from __future__ import annotations
25+
2426
import argparse
2527
import os
2628
import pathlib
@@ -44,7 +46,7 @@
4446

4547

4648
class _Parser(argparse.ArgumentParser):
47-
def print_help(self, file: Optional[IO[str]] = None) -> None:
49+
def print_help(self, file: IO[str] | None = None) -> None:
4850
super().print_help()
4951
print(
5052
dedent(
@@ -90,7 +92,7 @@ def create_parser() -> _Parser:
9092
return parser
9193

9294

93-
def get_config_and_history_file(namespace: argparse.Namespace) -> Tuple[str, str]:
95+
def get_config_and_history_file(namespace: argparse.Namespace) -> tuple[str, str]:
9496
"""
9597
Check which config/history files to use, ensure that the directories for
9698
these files exist, and return the config and history path.

ptpython/eventloop.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
in readline. ``prompt-toolkit`` doesn't understand that input hook, but this
88
will fix it for Tk.)
99
"""
10+
from __future__ import annotations
11+
1012
import sys
1113
import time
1214

ptpython/filters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import TYPE_CHECKING
24

35
from prompt_toolkit.filters import Filter
@@ -9,7 +11,7 @@
911

1012

1113
class PythonInputFilter(Filter):
12-
def __init__(self, python_input: "PythonInput") -> None:
14+
def __init__(self, python_input: PythonInput) -> None:
1315
super().__init__()
1416
self.python_input = python_input
1517

ptpython/history_browser.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
`create_history_application` creates an `Application` instance that runs will
55
run as a sub application of the Repl/PythonInput.
66
"""
7+
from __future__ import annotations
8+
79
from functools import partial
810
from typing import TYPE_CHECKING, Callable, List, Optional, Set
911

@@ -128,7 +130,7 @@ class HistoryLayout:
128130
application.
129131
"""
130132

131-
def __init__(self, history: "PythonHistory") -> None:
133+
def __init__(self, history: PythonHistory) -> None:
132134
search_toolbar = SearchToolbar()
133135

134136
self.help_buffer_control = BufferControl(
@@ -224,7 +226,7 @@ def _get_top_toolbar_fragments() -> StyleAndTextTuples:
224226
return [("class:status-bar.title", "History browser - Insert from history")]
225227

226228

227-
def _get_bottom_toolbar_fragments(history: "PythonHistory") -> StyleAndTextTuples:
229+
def _get_bottom_toolbar_fragments(history: PythonHistory) -> StyleAndTextTuples:
228230
python_input = history.python_input
229231

230232
@if_mousedown
@@ -258,7 +260,7 @@ class HistoryMargin(Margin):
258260
This displays a green bar for the selected entries.
259261
"""
260262

261-
def __init__(self, history: "PythonHistory") -> None:
263+
def __init__(self, history: PythonHistory) -> None:
262264
self.history_buffer = history.history_buffer
263265
self.history_mapping = history.history_mapping
264266

@@ -307,7 +309,7 @@ class ResultMargin(Margin):
307309
The margin to be shown in the result pane.
308310
"""
309311

310-
def __init__(self, history: "PythonHistory") -> None:
312+
def __init__(self, history: PythonHistory) -> None:
311313
self.history_mapping = history.history_mapping
312314
self.history_buffer = history.history_buffer
313315

@@ -356,7 +358,7 @@ class GrayExistingText(Processor):
356358
Turn the existing input, before and after the inserted code gray.
357359
"""
358360

359-
def __init__(self, history_mapping: "HistoryMapping") -> None:
361+
def __init__(self, history_mapping: HistoryMapping) -> None:
360362
self.history_mapping = history_mapping
361363
self._lines_before = len(
362364
history_mapping.original_document.text_before_cursor.splitlines()
@@ -384,7 +386,7 @@ class HistoryMapping:
384386

385387
def __init__(
386388
self,
387-
history: "PythonHistory",
389+
history: PythonHistory,
388390
python_history: History,
389391
original_document: Document,
390392
) -> None:
@@ -393,11 +395,11 @@ def __init__(
393395
self.original_document = original_document
394396

395397
self.lines_starting_new_entries = set()
396-
self.selected_lines: Set[int] = set()
398+
self.selected_lines: set[int] = set()
397399

398400
# Process history.
399401
history_strings = python_history.get_strings()
400-
history_lines: List[str] = []
402+
history_lines: list[str] = []
401403

402404
for entry_nr, entry in list(enumerate(history_strings))[-HISTORY_COUNT:]:
403405
self.lines_starting_new_entries.add(len(history_lines))
@@ -419,7 +421,7 @@ def __init__(
419421
else:
420422
self.result_line_offset = 0
421423

422-
def get_new_document(self, cursor_pos: Optional[int] = None) -> Document:
424+
def get_new_document(self, cursor_pos: int | None = None) -> Document:
423425
"""
424426
Create a `Document` instance that contains the resulting text.
425427
"""
@@ -449,7 +451,7 @@ def update_default_buffer(self) -> None:
449451
b.set_document(self.get_new_document(b.cursor_position), bypass_readonly=True)
450452

451453

452-
def _toggle_help(history: "PythonHistory") -> None:
454+
def _toggle_help(history: PythonHistory) -> None:
453455
"Display/hide help."
454456
help_buffer_control = history.history_layout.help_buffer_control
455457

@@ -459,7 +461,7 @@ def _toggle_help(history: "PythonHistory") -> None:
459461
history.app.layout.current_control = help_buffer_control
460462

461463

462-
def _select_other_window(history: "PythonHistory") -> None:
464+
def _select_other_window(history: PythonHistory) -> None:
463465
"Toggle focus between left/right window."
464466
current_buffer = history.app.current_buffer
465467
layout = history.history_layout.layout
@@ -472,8 +474,8 @@ def _select_other_window(history: "PythonHistory") -> None:
472474

473475

474476
def create_key_bindings(
475-
history: "PythonHistory",
476-
python_input: "PythonInput",
477+
history: PythonHistory,
478+
python_input: PythonInput,
477479
history_mapping: HistoryMapping,
478480
) -> KeyBindings:
479481
"""
@@ -592,9 +594,7 @@ def _(event: E) -> None:
592594

593595

594596
class PythonHistory:
595-
def __init__(
596-
self, python_input: "PythonInput", original_document: Document
597-
) -> None:
597+
def __init__(self, python_input: PythonInput, original_document: Document) -> None:
598598
"""
599599
Create an `Application` for the history screen.
600600
This has to be run as a sub application of `python_input`.

ptpython/ipython.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
offer.
99
1010
"""
11+
from __future__ import annotations
12+
1113
from typing import Iterable
1214
from warnings import warn
1315

@@ -62,12 +64,12 @@ def out_prompt(self) -> AnyFormattedText:
6264

6365
class IPythonValidator(PythonValidator):
6466
def __init__(self, *args, **kwargs):
65-
super(IPythonValidator, self).__init__(*args, **kwargs)
67+
super().__init__(*args, **kwargs)
6668
self.isp = IPythonInputSplitter()
6769

6870
def validate(self, document: Document) -> None:
6971
document = Document(text=self.isp.transform_cell(document.text))
70-
super(IPythonValidator, self).validate(document)
72+
super().validate(document)
7173

7274

7375
def create_ipython_grammar():

0 commit comments

Comments
 (0)