Skip to content

Commit 9b34424

Browse files
committed
Upgrade code to 3.9+
1 parent a4eadd7 commit 9b34424

29 files changed

+139
-135
lines changed

bpython/args.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ def log_version(module: ModuleType, name: str) -> None:
7373
logger.info("%s: %s", name, module.__version__ if hasattr(module, "__version__") else "unknown version") # type: ignore
7474

7575

76-
Options = Tuple[str, str, Callable[[argparse._ArgumentGroup], None]]
76+
Options = tuple[str, str, Callable[[argparse._ArgumentGroup], None]]
7777

7878

7979
def parse(
80-
args: Optional[List[str]],
80+
args: Optional[list[str]],
8181
extras: Optional[Options] = None,
8282
ignore_stdin: bool = False,
83-
) -> Tuple[Config, argparse.Namespace, List[str]]:
83+
) -> tuple[Config, argparse.Namespace, list[str]]:
8484
"""Receive an argument list - if None, use sys.argv - parse all args and
8585
take appropriate action. Also receive optional extra argument: this should
8686
be a tuple of (title, description, callback)
@@ -256,7 +256,7 @@ def callback(group):
256256

257257

258258
def exec_code(
259-
interpreter: code.InteractiveInterpreter, args: List[str]
259+
interpreter: code.InteractiveInterpreter, args: list[str]
260260
) -> None:
261261
"""
262262
Helper to execute code in a given interpreter, e.g. to implement the behavior of python3 [-i] file.py

bpython/autocomplete.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
from typing import (
4141
Any,
4242
Dict,
43-
Iterator,
4443
List,
4544
Optional,
46-
Sequence,
4745
Set,
4846
Tuple,
4947
)
48+
from collections.abc import Iterator, Sequence
49+
5050
from . import inspection
5151
from . import line as lineparts
5252
from .line import LinePart
@@ -236,7 +236,7 @@ def __init__(
236236
@abc.abstractmethod
237237
def matches(
238238
self, cursor_offset: int, line: str, **kwargs: Any
239-
) -> Optional[Set[str]]:
239+
) -> Optional[set[str]]:
240240
"""Returns a list of possible matches given a line and cursor, or None
241241
if this completion type isn't applicable.
242242
@@ -268,7 +268,7 @@ def format(self, word: str) -> str:
268268

269269
def substitute(
270270
self, cursor_offset: int, line: str, match: str
271-
) -> Tuple[int, str]:
271+
) -> tuple[int, str]:
272272
"""Returns a cursor offset and line with match swapped in"""
273273
lpart = self.locate(cursor_offset, line)
274274
assert lpart
@@ -311,7 +311,7 @@ def format(self, word: str) -> str:
311311

312312
def matches(
313313
self, cursor_offset: int, line: str, **kwargs: Any
314-
) -> Optional[Set[str]]:
314+
) -> Optional[set[str]]:
315315
return_value = None
316316
all_matches = set()
317317
for completer in self._completers:
@@ -336,7 +336,7 @@ def __init__(
336336

337337
def matches(
338338
self, cursor_offset: int, line: str, **kwargs: Any
339-
) -> Optional[Set[str]]:
339+
) -> Optional[set[str]]:
340340
return self.module_gatherer.complete(cursor_offset, line)
341341

342342
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
@@ -356,7 +356,7 @@ def __init__(self, mode: AutocompleteModes = AutocompleteModes.SIMPLE):
356356

357357
def matches(
358358
self, cursor_offset: int, line: str, **kwargs: Any
359-
) -> Optional[Set[str]]:
359+
) -> Optional[set[str]]:
360360
cs = lineparts.current_string(cursor_offset, line)
361361
if cs is None:
362362
return None
@@ -389,9 +389,9 @@ def matches(
389389
cursor_offset: int,
390390
line: str,
391391
*,
392-
locals_: Optional[Dict[str, Any]] = None,
392+
locals_: Optional[dict[str, Any]] = None,
393393
**kwargs: Any,
394-
) -> Optional[Set[str]]:
394+
) -> Optional[set[str]]:
395395
r = self.locate(cursor_offset, line)
396396
if r is None:
397397
return None
@@ -421,7 +421,7 @@ def format(self, word: str) -> str:
421421
return _after_last_dot(word)
422422

423423
def attr_matches(
424-
self, text: str, namespace: Dict[str, Any]
424+
self, text: str, namespace: dict[str, Any]
425425
) -> Iterator[str]:
426426
"""Taken from rlcompleter.py and bent to my will."""
427427

@@ -460,7 +460,7 @@ def attr_lookup(self, obj: Any, expr: str, attr: str) -> Iterator[str]:
460460
if self.method_match(word, n, attr) and word != "__builtins__"
461461
)
462462

463-
def list_attributes(self, obj: Any) -> List[str]:
463+
def list_attributes(self, obj: Any) -> list[str]:
464464
# TODO: re-implement dir without AttrCleaner here
465465
#
466466
# Note: accessing `obj.__dir__` via `getattr_static` is not side-effect free.
@@ -474,9 +474,9 @@ def matches(
474474
cursor_offset: int,
475475
line: str,
476476
*,
477-
locals_: Optional[Dict[str, Any]] = None,
477+
locals_: Optional[dict[str, Any]] = None,
478478
**kwargs: Any,
479-
) -> Optional[Set[str]]:
479+
) -> Optional[set[str]]:
480480
if locals_ is None:
481481
return None
482482

@@ -516,7 +516,7 @@ def matches(
516516
current_block: Optional[str] = None,
517517
complete_magic_methods: Optional[bool] = None,
518518
**kwargs: Any,
519-
) -> Optional[Set[str]]:
519+
) -> Optional[set[str]]:
520520
if (
521521
current_block is None
522522
or complete_magic_methods is None
@@ -541,9 +541,9 @@ def matches(
541541
cursor_offset: int,
542542
line: str,
543543
*,
544-
locals_: Optional[Dict[str, Any]] = None,
544+
locals_: Optional[dict[str, Any]] = None,
545545
**kwargs: Any,
546-
) -> Optional[Set[str]]:
546+
) -> Optional[set[str]]:
547547
"""Compute matches when text is a simple name.
548548
Return a list of all keywords, built-in functions and names currently
549549
defined in self.namespace that match.
@@ -583,7 +583,7 @@ def matches(
583583
*,
584584
funcprops: Optional[inspection.FuncProps] = None,
585585
**kwargs: Any,
586-
) -> Optional[Set[str]]:
586+
) -> Optional[set[str]]:
587587
if funcprops is None:
588588
return None
589589

@@ -622,9 +622,9 @@ def matches(
622622
cursor_offset: int,
623623
line: str,
624624
*,
625-
locals_: Optional[Dict[str, Any]] = None,
625+
locals_: Optional[dict[str, Any]] = None,
626626
**kwargs: Any,
627-
) -> Optional[Set[str]]:
627+
) -> Optional[set[str]]:
628628
if locals_ is None:
629629
locals_ = __main__.__dict__
630630

@@ -648,7 +648,7 @@ def matches(
648648
class MultilineJediCompletion(BaseCompletionType): # type: ignore [no-redef]
649649
def matches(
650650
self, cursor_offset: int, line: str, **kwargs: Any
651-
) -> Optional[Set[str]]:
651+
) -> Optional[set[str]]:
652652
return None
653653

654654
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
@@ -665,9 +665,9 @@ def matches(
665665
line: str,
666666
*,
667667
current_block: Optional[str] = None,
668-
history: Optional[List[str]] = None,
668+
history: Optional[list[str]] = None,
669669
**kwargs: Any,
670-
) -> Optional[Set[str]]:
670+
) -> Optional[set[str]]:
671671
if (
672672
current_block is None
673673
or history is None
@@ -725,12 +725,12 @@ def get_completer(
725725
cursor_offset: int,
726726
line: str,
727727
*,
728-
locals_: Optional[Dict[str, Any]] = None,
728+
locals_: Optional[dict[str, Any]] = None,
729729
argspec: Optional[inspection.FuncProps] = None,
730-
history: Optional[List[str]] = None,
730+
history: Optional[list[str]] = None,
731731
current_block: Optional[str] = None,
732732
complete_magic_methods: Optional[bool] = None,
733-
) -> Tuple[List[str], Optional[BaseCompletionType]]:
733+
) -> tuple[list[str], Optional[BaseCompletionType]]:
734734
"""Returns a list of matches and an applicable completer
735735
736736
If no matches available, returns a tuple of an empty list and None
@@ -747,7 +747,7 @@ def get_completer(
747747
double underscore methods like __len__ in method signatures
748748
"""
749749

750-
def _cmpl_sort(x: str) -> Tuple[bool, str]:
750+
def _cmpl_sort(x: str) -> tuple[bool, str]:
751751
"""
752752
Function used to sort the matches.
753753
"""
@@ -784,7 +784,7 @@ def _cmpl_sort(x: str) -> Tuple[bool, str]:
784784

785785
def get_default_completer(
786786
mode: AutocompleteModes, module_gatherer: ModuleGatherer
787-
) -> Tuple[BaseCompletionType, ...]:
787+
) -> tuple[BaseCompletionType, ...]:
788788
return (
789789
(
790790
DictKeyCompletion(mode=mode),

bpython/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
from configparser import ConfigParser
3232
from itertools import chain
3333
from pathlib import Path
34-
from typing import MutableMapping, Mapping, Any, Dict
34+
from typing import Any, Dict
35+
from collections.abc import MutableMapping, Mapping
3536
from xdg import BaseDirectory
3637

3738
from .autocomplete import AutocompleteModes
@@ -115,7 +116,7 @@ class Config:
115116
"right_arrow_suggestion": "K",
116117
}
117118

118-
defaults: Dict[str, Dict[str, Any]] = {
119+
defaults: dict[str, dict[str, Any]] = {
119120
"general": {
120121
"arg_spec": True,
121122
"auto_display_list": True,

bpython/curtsies.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
Any,
2626
Callable,
2727
Dict,
28-
Generator,
2928
List,
3029
Optional,
3130
Protocol,
32-
Sequence,
3331
Tuple,
3432
Union,
3533
)
34+
from collections.abc import Generator, Sequence
3635

3736
logger = logging.getLogger(__name__)
3837

@@ -51,7 +50,7 @@ class FullCurtsiesRepl(BaseRepl):
5150
def __init__(
5251
self,
5352
config: Config,
54-
locals_: Optional[Dict[str, Any]] = None,
53+
locals_: Optional[dict[str, Any]] = None,
5554
banner: Optional[str] = None,
5655
interp: Optional[Interp] = None,
5756
) -> None:
@@ -111,7 +110,7 @@ def interrupting_refresh(self) -> None:
111110
def request_undo(self, n: int = 1) -> None:
112111
return self._request_undo_callback(n=n)
113112

114-
def get_term_hw(self) -> Tuple[int, int]:
113+
def get_term_hw(self) -> tuple[int, int]:
115114
return self.window.get_term_hw()
116115

117116
def get_cursor_vertical_diff(self) -> int:
@@ -179,8 +178,8 @@ def mainloop(
179178

180179

181180
def main(
182-
args: Optional[List[str]] = None,
183-
locals_: Optional[Dict[str, Any]] = None,
181+
args: Optional[list[str]] = None,
182+
locals_: Optional[dict[str, Any]] = None,
184183
banner: Optional[str] = None,
185184
welcome_message: Optional[str] = None,
186185
) -> Any:
@@ -209,7 +208,7 @@ def curtsies_arguments(parser: argparse._ArgumentGroup) -> None:
209208

210209
interp = None
211210
paste = None
212-
exit_value: Tuple[Any, ...] = ()
211+
exit_value: tuple[Any, ...] = ()
213212
if exec_args:
214213
if not options:
215214
raise ValueError("don't pass in exec_args without options")

bpython/curtsiesfrontend/_internal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __enter__(self):
3434

3535
def __exit__(
3636
self,
37-
exc_type: Optional[Type[BaseException]],
37+
exc_type: Optional[type[BaseException]],
3838
exc_val: Optional[BaseException],
3939
exc_tb: Optional[TracebackType],
4040
) -> Literal[False]:

bpython/curtsiesfrontend/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Non-keyboard events used in bpython curtsies REPL"""
22

33
import time
4-
from typing import Sequence
4+
from collections.abc import Sequence
55

66
import curtsies.events
77

bpython/curtsiesfrontend/filewatch.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from collections import defaultdict
3-
from typing import Callable, Dict, Iterable, Sequence, Set, List
3+
from typing import Callable, Dict, Set, List
4+
from collections.abc import Iterable, Sequence
45

56
from .. import importcompletion
67

@@ -20,9 +21,9 @@ def __init__(
2021
paths: Iterable[str],
2122
on_change: Callable[[Sequence[str]], None],
2223
) -> None:
23-
self.dirs: Dict[str, Set[str]] = defaultdict(set)
24+
self.dirs: dict[str, set[str]] = defaultdict(set)
2425
self.on_change = on_change
25-
self.modules_to_add_later: List[str] = []
26+
self.modules_to_add_later: list[str] = []
2627
self.observer = Observer()
2728
self.started = False
2829
self.activated = False

bpython/curtsiesfrontend/interpreter.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
from codeop import CommandCompiler
3-
from typing import Any, Dict, Iterable, Optional, Tuple, Union
3+
from typing import Any, Dict, Optional, Tuple, Union
4+
from collections.abc import Iterable
45

56
from pygments.token import Generic, Token, Keyword, Name, Comment, String
67
from pygments.token import Error, Literal, Number, Operator, Punctuation
@@ -47,7 +48,7 @@ class BPythonFormatter(Formatter):
4748

4849
def __init__(
4950
self,
50-
color_scheme: Dict[_TokenType, str],
51+
color_scheme: dict[_TokenType, str],
5152
**options: Union[str, bool, None],
5253
) -> None:
5354
self.f_strings = {k: f"\x01{v}" for k, v in color_scheme.items()}
@@ -67,7 +68,7 @@ def format(self, tokensource, outfile):
6768
class Interp(ReplInterpreter):
6869
def __init__(
6970
self,
70-
locals: Optional[Dict[str, Any]] = None,
71+
locals: Optional[dict[str, Any]] = None,
7172
) -> None:
7273
"""Constructor.
7374
@@ -121,7 +122,7 @@ def format(self, tbtext: str, lexer: Any) -> None:
121122

122123
def code_finished_will_parse(
123124
s: str, compiler: CommandCompiler
124-
) -> Tuple[bool, bool]:
125+
) -> tuple[bool, bool]:
125126
"""Returns a tuple of whether the buffer could be complete and whether it
126127
will parse
127128

bpython/curtsiesfrontend/parse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def parse(s: str) -> FmtStr:
6060
)
6161

6262

63-
def fs_from_match(d: Dict[str, Any]) -> FmtStr:
63+
def fs_from_match(d: dict[str, Any]) -> FmtStr:
6464
atts = {}
6565
color = "default"
6666
if d["fg"]:
@@ -99,7 +99,7 @@ def fs_from_match(d: Dict[str, Any]) -> FmtStr:
9999
)
100100

101101

102-
def peel_off_string(s: str) -> Tuple[Dict[str, Any], str]:
102+
def peel_off_string(s: str) -> tuple[dict[str, Any], str]:
103103
m = peel_off_string_re.match(s)
104104
assert m, repr(s)
105105
d = m.groupdict()

0 commit comments

Comments
 (0)