Skip to content

Commit 982bd7e

Browse files
committed
Upgrade to Python 3.10+
1 parent b995623 commit 982bd7e

23 files changed

+157
-169
lines changed

bpython/args.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
import os
3737
import sys
3838
from pathlib import Path
39-
from typing import Tuple, List, Optional, Callable
39+
from typing import Tuple, List, Optional
40+
from collections.abc import Callable
4041
from types import ModuleType
4142

4243
from . import __version__, __copyright__
@@ -77,8 +78,8 @@ def log_version(module: ModuleType, name: str) -> None:
7778

7879

7980
def parse(
80-
args: Optional[list[str]],
81-
extras: Optional[Options] = None,
81+
args: list[str] | None,
82+
extras: Options | None = None,
8283
ignore_stdin: bool = False,
8384
) -> tuple[Config, argparse.Namespace, list[str]]:
8485
"""Receive an argument list - if None, use sys.argv - parse all args and

bpython/autocomplete.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
) -> set[str] | None:
240240
"""Returns a list of possible matches given a line and cursor, or None
241241
if this completion type isn't applicable.
242242
@@ -255,7 +255,7 @@ def matches(
255255
raise NotImplementedError
256256

257257
@abc.abstractmethod
258-
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
258+
def locate(self, cursor_offset: int, line: str) -> LinePart | None:
259259
"""Returns a Linepart namedtuple instance or None given cursor and line
260260
261261
A Linepart namedtuple contains a start, stop, and word. None is
@@ -299,7 +299,7 @@ def __init__(
299299

300300
super().__init__(True, mode)
301301

302-
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
302+
def locate(self, cursor_offset: int, line: str) -> LinePart | None:
303303
for completer in self._completers:
304304
return_value = completer.locate(cursor_offset, line)
305305
if return_value is not None:
@@ -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+
) -> set[str] | None:
315315
return_value = None
316316
all_matches = set()
317317
for completer in self._completers:
@@ -336,10 +336,10 @@ def __init__(
336336

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

342-
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
342+
def locate(self, cursor_offset: int, line: str) -> LinePart | None:
343343
return lineparts.current_word(cursor_offset, line)
344344

345345
def format(self, word: str) -> str:
@@ -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+
) -> set[str] | None:
360360
cs = lineparts.current_string(cursor_offset, line)
361361
if cs is None:
362362
return None
@@ -371,7 +371,7 @@ def matches(
371371
matches.add(filename)
372372
return matches
373373

374-
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
374+
def locate(self, cursor_offset: int, line: str) -> LinePart | None:
375375
return lineparts.current_string(cursor_offset, line)
376376

377377
def format(self, filename: str) -> str:
@@ -389,9 +389,9 @@ def matches(
389389
cursor_offset: int,
390390
line: str,
391391
*,
392-
locals_: Optional[dict[str, Any]] = None,
392+
locals_: dict[str, Any] | None = None,
393393
**kwargs: Any,
394-
) -> Optional[set[str]]:
394+
) -> set[str] | None:
395395
r = self.locate(cursor_offset, line)
396396
if r is None:
397397
return None
@@ -414,7 +414,7 @@ def matches(
414414
if _few_enough_underscores(r.word.split(".")[-1], m.split(".")[-1])
415415
}
416416

417-
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
417+
def locate(self, cursor_offset: int, line: str) -> LinePart | None:
418418
return lineparts.current_dotted_attribute(cursor_offset, line)
419419

420420
def format(self, word: str) -> str:
@@ -474,9 +474,9 @@ def matches(
474474
cursor_offset: int,
475475
line: str,
476476
*,
477-
locals_: Optional[dict[str, Any]] = None,
477+
locals_: dict[str, Any] | None = None,
478478
**kwargs: Any,
479-
) -> Optional[set[str]]:
479+
) -> set[str] | None:
480480
if locals_ is None:
481481
return None
482482

@@ -500,7 +500,7 @@ def matches(
500500
else:
501501
return None
502502

503-
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
503+
def locate(self, cursor_offset: int, line: str) -> LinePart | None:
504504
return lineparts.current_dict_key(cursor_offset, line)
505505

506506
def format(self, match: str) -> str:
@@ -513,10 +513,10 @@ def matches(
513513
cursor_offset: int,
514514
line: str,
515515
*,
516-
current_block: Optional[str] = None,
517-
complete_magic_methods: Optional[bool] = None,
516+
current_block: str | None = None,
517+
complete_magic_methods: bool | None = None,
518518
**kwargs: Any,
519-
) -> Optional[set[str]]:
519+
) -> set[str] | None:
520520
if (
521521
current_block is None
522522
or complete_magic_methods is None
@@ -531,7 +531,7 @@ def matches(
531531
return None
532532
return {name for name in MAGIC_METHODS if name.startswith(r.word)}
533533

534-
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
534+
def locate(self, cursor_offset: int, line: str) -> LinePart | None:
535535
return lineparts.current_method_definition_name(cursor_offset, line)
536536

537537

@@ -541,9 +541,9 @@ def matches(
541541
cursor_offset: int,
542542
line: str,
543543
*,
544-
locals_: Optional[dict[str, Any]] = None,
544+
locals_: dict[str, Any] | None = None,
545545
**kwargs: Any,
546-
) -> Optional[set[str]]:
546+
) -> set[str] | None:
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.
@@ -571,7 +571,7 @@ def matches(
571571
matches.add(_callable_postfix(val, word))
572572
return matches if matches else None
573573

574-
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
574+
def locate(self, cursor_offset: int, line: str) -> LinePart | None:
575575
return lineparts.current_single_word(cursor_offset, line)
576576

577577

@@ -581,9 +581,9 @@ def matches(
581581
cursor_offset: int,
582582
line: str,
583583
*,
584-
funcprops: Optional[inspection.FuncProps] = None,
584+
funcprops: inspection.FuncProps | None = None,
585585
**kwargs: Any,
586-
) -> Optional[set[str]]:
586+
) -> set[str] | None:
587587
if funcprops is None:
588588
return None
589589

@@ -603,7 +603,7 @@ def matches(
603603
)
604604
return matches if matches else None
605605

606-
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
606+
def locate(self, cursor_offset: int, line: str) -> LinePart | None:
607607
r = lineparts.current_word(cursor_offset, line)
608608
if r and r.word[-1] == "(":
609609
# if the word ends with a (, it's the parent word with an empty
@@ -614,17 +614,17 @@ def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
614614

615615
class ExpressionAttributeCompletion(AttrCompletion):
616616
# could replace attr completion as a more general case with some work
617-
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
617+
def locate(self, cursor_offset: int, line: str) -> LinePart | None:
618618
return lineparts.current_expression_attribute(cursor_offset, line)
619619

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

@@ -648,26 +648,26 @@ 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+
) -> set[str] | None:
652652
return None
653653

654-
def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
654+
def locate(self, cursor_offset: int, line: str) -> LinePart | None:
655655
return None
656656

657657
else:
658658

659659
class MultilineJediCompletion(BaseCompletionType): # type: ignore [no-redef]
660-
_orig_start: Optional[int]
660+
_orig_start: int | None
661661

662662
def matches(
663663
self,
664664
cursor_offset: int,
665665
line: str,
666666
*,
667-
current_block: Optional[str] = None,
668-
history: Optional[list[str]] = None,
667+
current_block: str | None = None,
668+
history: list[str] | None = None,
669669
**kwargs: Any,
670-
) -> Optional[set[str]]:
670+
) -> set[str] | None:
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,
729-
argspec: Optional[inspection.FuncProps] = None,
730-
history: Optional[list[str]] = None,
731-
current_block: Optional[str] = None,
732-
complete_magic_methods: Optional[bool] = None,
733-
) -> tuple[list[str], Optional[BaseCompletionType]]:
728+
locals_: dict[str, Any] | None = None,
729+
argspec: inspection.FuncProps | None = None,
730+
history: list[str] | None = None,
731+
current_block: str | None = None,
732+
complete_magic_methods: bool | None = None,
733+
) -> tuple[list[str], BaseCompletionType | None]:
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

bpython/curtsies.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,35 @@
2323

2424
from typing import (
2525
Any,
26-
Callable,
2726
Dict,
2827
List,
2928
Optional,
3029
Protocol,
3130
Tuple,
3231
Union,
3332
)
34-
from collections.abc import Generator, Sequence
33+
from collections.abc import Callable, Generator, Sequence
3534

3635
logger = logging.getLogger(__name__)
3736

3837

3938
class SupportsEventGeneration(Protocol):
4039
def send(
41-
self, timeout: Optional[float]
42-
) -> Union[str, curtsies.events.Event, None]: ...
40+
self, timeout: float | None
41+
) -> str | curtsies.events.Event | None: ...
4342

4443
def __iter__(self) -> "SupportsEventGeneration": ...
4544

46-
def __next__(self) -> Union[str, curtsies.events.Event, None]: ...
45+
def __next__(self) -> str | curtsies.events.Event | None: ...
4746

4847

4948
class FullCurtsiesRepl(BaseRepl):
5049
def __init__(
5150
self,
5251
config: Config,
53-
locals_: Optional[dict[str, Any]] = None,
54-
banner: Optional[str] = None,
55-
interp: Optional[Interp] = None,
52+
locals_: dict[str, Any] | None = None,
53+
banner: str | None = None,
54+
interp: Interp | None = None,
5655
) -> None:
5756
self.input_generator = curtsies.input.Input(
5857
keynames="curtsies", sigint_event=True, paste_threshold=None
@@ -129,7 +128,7 @@ def after_suspend(self) -> None:
129128
self.interrupting_refresh()
130129

131130
def process_event_and_paint(
132-
self, e: Union[str, curtsies.events.Event, None]
131+
self, e: str | curtsies.events.Event | None
133132
) -> None:
134133
"""If None is passed in, just paint the screen"""
135134
try:
@@ -151,7 +150,7 @@ def process_event_and_paint(
151150
def mainloop(
152151
self,
153152
interactive: bool = True,
154-
paste: Optional[curtsies.events.PasteEvent] = None,
153+
paste: curtsies.events.PasteEvent | None = None,
155154
) -> None:
156155
if interactive:
157156
# Add custom help command
@@ -178,10 +177,10 @@ def mainloop(
178177

179178

180179
def main(
181-
args: Optional[list[str]] = None,
182-
locals_: Optional[dict[str, Any]] = None,
183-
banner: Optional[str] = None,
184-
welcome_message: Optional[str] = None,
180+
args: list[str] | None = None,
181+
locals_: dict[str, Any] | None = None,
182+
banner: str | None = None,
183+
welcome_message: str | None = None,
185184
) -> Any:
186185
"""
187186
banner is displayed directly after the version information.
@@ -249,7 +248,7 @@ def curtsies_arguments(parser: argparse._ArgumentGroup) -> None:
249248

250249
def _combined_events(
251250
event_provider: SupportsEventGeneration, paste_threshold: int
252-
) -> Generator[Union[str, curtsies.events.Event, None], Optional[float], None]:
251+
) -> Generator[str | curtsies.events.Event | None, float | None, None]:
253252
"""Combines consecutive keypress events into paste events."""
254253
timeout = yield "nonsense_event" # so send can be used immediately
255254
queue: collections.deque = collections.deque()

bpython/curtsiesfrontend/_internal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def __enter__(self):
3434

3535
def __exit__(
3636
self,
37-
exc_type: Optional[type[BaseException]],
38-
exc_val: Optional[BaseException],
39-
exc_tb: Optional[TracebackType],
37+
exc_type: type[BaseException] | None,
38+
exc_val: BaseException | None,
39+
exc_tb: TracebackType | None,
4040
) -> Literal[False]:
4141
pydoc.pager = self._orig_pager
4242
return False

bpython/curtsiesfrontend/filewatch.py

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

66
from .. import importcompletion
77

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy