Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/_pyrepl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ def is_soft_keyword_used(*tokens: TI | None) -> bool:
return True
case (TI(string="case"), TI(string="_"), TI(string=":")):
return True
case (
None | TI(T.NEWLINE) | TI(T.INDENT) | TI(T.DEDENT) | TI(string=":"),
TI(string="type"),
TI(T.NAME, string=s)
):
return not keyword.iskeyword(s)
case _:
return False

Expand Down
8 changes: 5 additions & 3 deletions Lib/test/test_pyrepl/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def funct(case: str = sys.platform) -> None:
case "ios" | "android":
print("on the phone")
case _: print('arms around', match.group(1))
type type = type[type]
"""
)
expected = dedent(
Expand All @@ -397,21 +398,22 @@ def funct(case: str = sys.platform) -> None:
{K}case{z} {s}"ios"{z} {o}|{z} {s}"android"{z}{o}:{z}
{b}print{z}{o}({z}{s}"on the phone"{z}{o}){z}
{K}case{z} {K}_{z}{o}:{z} {b}print{z}{o}({z}{s}'arms around'{z}{o},{z} match{o}.{z}group{o}({z}{n}1{z}{o}){z}{o}){z}
{K}type{z} {b}type{z} {o}={z} {b}type{z}{o}[{z}{b}type{z}{o}]{z}
"""
)
expected_sync = expected.format(a="", **colors)
events = code_to_events(code)
reader, _ = handle_all_events(events)
self.assert_screen_equal(reader, code, clean=True)
self.assert_screen_equal(reader, expected_sync)
self.assertEqual(reader.pos, 396)
self.assertEqual(reader.cxy, (0, 15))
self.assertEqual(reader.pos, 419)
self.assertEqual(reader.cxy, (0, 16))

async_msg = "{k}async{z} ".format(**colors)
expected_async = expected.format(a=async_msg, **colors)
more_events = itertools.chain(
code_to_events(code),
[Event(evt="key", data="up", raw=bytearray(b"\x1bOA"))] * 14,
[Event(evt="key", data="up", raw=bytearray(b"\x1bOA"))] * 15,
code_to_events("async "),
)
reader, _ = handle_all_events(more_events)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The REPL now highlights :keyword:`type` as a soft keyword
in :ref:`type statements <type>`.
Loading