Skip to content

Commit c10b99b

Browse files
kingileryouknowone
authored andcommitted
Update keyword.py and test_keyword.py from CPython v3.12.0
1 parent bca90f1 commit c10b99b

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎Lib/keyword.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
softkwlist = [
5757
'_',
5858
'case',
59-
'match'
59+
'match',
60+
'type'
6061
]
6162

6263
iskeyword = frozenset(kwlist).__contains__

‎Lib/test/test_keyword.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,37 @@ def test_changing_the_kwlist_does_not_affect_iskeyword(self):
2020
keyword.kwlist = ['its', 'all', 'eggs', 'beans', 'and', 'a', 'slice']
2121
self.assertFalse(keyword.iskeyword('eggs'))
2222

23+
def test_changing_the_softkwlist_does_not_affect_issoftkeyword(self):
24+
oldlist = keyword.softkwlist
25+
self.addCleanup(setattr, keyword, "softkwlist", oldlist)
26+
keyword.softkwlist = ["foo", "bar", "spam", "egs", "case"]
27+
self.assertFalse(keyword.issoftkeyword("spam"))
28+
2329
def test_all_keywords_fail_to_be_used_as_names(self):
2430
for key in keyword.kwlist:
2531
with self.assertRaises(SyntaxError):
2632
exec(f"{key} = 42")
2733

34+
def test_all_soft_keywords_can_be_used_as_names(self):
35+
for key in keyword.softkwlist:
36+
exec(f"{key} = 42")
37+
2838
def test_async_and_await_are_keywords(self):
2939
self.assertIn("async", keyword.kwlist)
3040
self.assertIn("await", keyword.kwlist)
3141

42+
def test_soft_keywords(self):
43+
self.assertIn("type", keyword.softkwlist)
44+
self.assertIn("match", keyword.softkwlist)
45+
self.assertIn("case", keyword.softkwlist)
46+
self.assertIn("_", keyword.softkwlist)
47+
3248
def test_keywords_are_sorted(self):
3349
self.assertListEqual(sorted(keyword.kwlist), keyword.kwlist)
3450

51+
def test_softkeywords_are_sorted(self):
52+
self.assertListEqual(sorted(keyword.softkwlist), keyword.softkwlist)
53+
3554

3655
if __name__ == "__main__":
3756
unittest.main()

0 commit comments

Comments
 (0)