mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Update keyword.py and test_keyword.py from CPython v3.12.0
This commit is contained in:
1 parent
bca90f191c
commit
c10b99b29a
2 files changed
+21
-1
No files matched your search
Vendored
+2
-1
@@ -56,7 +56,8 @@ kwlist = [
|
||||
softkwlist = [
|
||||
'_',
|
||||
'case',
|
||||
'match'
|
||||
'match',
|
||||
'type'
|
||||
]
|
||||
|
||||
iskeyword = frozenset(kwlist).__contains__
|
||||
|
||||
Vendored
+19
@@ -20,18 +20,37 @@ class Test_iskeyword(unittest.TestCase):
|
||||
keyword.kwlist = ['its', 'all', 'eggs', 'beans', 'and', 'a', 'slice']
|
||||
self.assertFalse(keyword.iskeyword('eggs'))
|
||||
|
||||
def test_changing_the_softkwlist_does_not_affect_issoftkeyword(self):
|
||||
oldlist = keyword.softkwlist
|
||||
self.addCleanup(setattr, keyword, "softkwlist", oldlist)
|
||||
keyword.softkwlist = ["foo", "bar", "spam", "egs", "case"]
|
||||
self.assertFalse(keyword.issoftkeyword("spam"))
|
||||
|
||||
def test_all_keywords_fail_to_be_used_as_names(self):
|
||||
for key in keyword.kwlist:
|
||||
with self.assertRaises(SyntaxError):
|
||||
exec(f"{key} = 42")
|
||||
|
||||
def test_all_soft_keywords_can_be_used_as_names(self):
|
||||
for key in keyword.softkwlist:
|
||||
exec(f"{key} = 42")
|
||||
|
||||
def test_async_and_await_are_keywords(self):
|
||||
self.assertIn("async", keyword.kwlist)
|
||||
self.assertIn("await", keyword.kwlist)
|
||||
|
||||
def test_soft_keywords(self):
|
||||
self.assertIn("type", keyword.softkwlist)
|
||||
self.assertIn("match", keyword.softkwlist)
|
||||
self.assertIn("case", keyword.softkwlist)
|
||||
self.assertIn("_", keyword.softkwlist)
|
||||
|
||||
def test_keywords_are_sorted(self):
|
||||
self.assertListEqual(sorted(keyword.kwlist), keyword.kwlist)
|
||||
|
||||
def test_softkeywords_are_sorted(self):
|
||||
self.assertListEqual(sorted(keyword.softkwlist), keyword.softkwlist)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user