From 2bfbfd7a035b3203e39417cf8afafe350b30d71a Mon Sep 17 00:00:00 2001 From: NakanoMiku39 Date: Wed, 8 Nov 2023 19:25:01 +0800 Subject: [PATCH 1/9] Update test__locale.py from CPython v3.12 --- Lib/test/test_locale.py | 118 ++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 71 deletions(-) diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py index bc8a7a35fb..b0d7998559 100644 --- a/Lib/test/test_locale.py +++ b/Lib/test/test_locale.py @@ -141,18 +141,9 @@ class BaseFormattingTest(object): # Utility functions for formatting tests # - def _test_formatfunc(self, format, value, out, func, **format_opts): - self.assertEqual( - func(format, value, **format_opts), out) - - def _test_format(self, format, value, out, **format_opts): - with check_warnings(('', DeprecationWarning)): - self._test_formatfunc(format, value, out, - func=locale.format, **format_opts) - def _test_format_string(self, format, value, out, **format_opts): - self._test_formatfunc(format, value, out, - func=locale.format_string, **format_opts) + self.assertEqual( + locale.format_string(format, value, **format_opts), out) def _test_currency(self, value, out, **format_opts): self.assertEqual(locale.currency(value, **format_opts), out) @@ -166,44 +157,40 @@ def setUp(self): self.sep = locale.localeconv()['thousands_sep'] def test_grouping(self): - self._test_format("%f", 1024, grouping=1, out='1%s024.000000' % self.sep) - self._test_format("%f", 102, grouping=1, out='102.000000') - self._test_format("%f", -42, grouping=1, out='-42.000000') - self._test_format("%+f", -42, grouping=1, out='-42.000000') + self._test_format_string("%f", 1024, grouping=1, out='1%s024.000000' % self.sep) + self._test_format_string("%f", 102, grouping=1, out='102.000000') + self._test_format_string("%f", -42, grouping=1, out='-42.000000') + self._test_format_string("%+f", -42, grouping=1, out='-42.000000') def test_grouping_and_padding(self): - self._test_format("%20.f", -42, grouping=1, out='-42'.rjust(20)) + self._test_format_string("%20.f", -42, grouping=1, out='-42'.rjust(20)) if self.sep: - self._test_format("%+10.f", -4200, grouping=1, + self._test_format_string("%+10.f", -4200, grouping=1, out=('-4%s200' % self.sep).rjust(10)) - self._test_format("%-10.f", -4200, grouping=1, + self._test_format_string("%-10.f", -4200, grouping=1, out=('-4%s200' % self.sep).ljust(10)) def test_integer_grouping(self): - self._test_format("%d", 4200, grouping=True, out='4%s200' % self.sep) - self._test_format("%+d", 4200, grouping=True, out='+4%s200' % self.sep) - self._test_format("%+d", -4200, grouping=True, out='-4%s200' % self.sep) + self._test_format_string("%d", 4200, grouping=True, out='4%s200' % self.sep) + self._test_format_string("%+d", 4200, grouping=True, out='+4%s200' % self.sep) + self._test_format_string("%+d", -4200, grouping=True, out='-4%s200' % self.sep) def test_integer_grouping_and_padding(self): - self._test_format("%10d", 4200, grouping=True, + self._test_format_string("%10d", 4200, grouping=True, out=('4%s200' % self.sep).rjust(10)) - self._test_format("%-10d", -4200, grouping=True, + self._test_format_string("%-10d", -4200, grouping=True, out=('-4%s200' % self.sep).ljust(10)) def test_simple(self): - self._test_format("%f", 1024, grouping=0, out='1024.000000') - self._test_format("%f", 102, grouping=0, out='102.000000') - self._test_format("%f", -42, grouping=0, out='-42.000000') - self._test_format("%+f", -42, grouping=0, out='-42.000000') + self._test_format_string("%f", 1024, grouping=0, out='1024.000000') + self._test_format_string("%f", 102, grouping=0, out='102.000000') + self._test_format_string("%f", -42, grouping=0, out='-42.000000') + self._test_format_string("%+f", -42, grouping=0, out='-42.000000') def test_padding(self): - self._test_format("%20.f", -42, grouping=0, out='-42'.rjust(20)) - self._test_format("%+10.f", -4200, grouping=0, out='-4200'.rjust(10)) - self._test_format("%-10.f", 4200, grouping=0, out='4200'.ljust(10)) - - def test_format_deprecation(self): - with self.assertWarns(DeprecationWarning): - locale.format("%-10.f", 4200, grouping=True) + self._test_format_string("%20.f", -42, grouping=0, out='-42'.rjust(20)) + self._test_format_string("%+10.f", -4200, grouping=0, out='-4200'.rjust(10)) + self._test_format_string("%-10.f", 4200, grouping=0, out='4200'.ljust(10)) def test_complex_formatting(self): # Spaces in formatting string @@ -230,20 +217,9 @@ def test_complex_formatting(self): out='int 1%s000 float 1%s000.00 str str' % (self.sep, self.sep)) - -class TestFormatPatternArg(unittest.TestCase): - # Test handling of pattern argument of format - - def test_onlyOnePattern(self): - with check_warnings(('', DeprecationWarning)): - # Issue 2522: accept exactly one % pattern, and no extra chars. - self.assertRaises(ValueError, locale.format, "%f\n", 'foo') - self.assertRaises(ValueError, locale.format, "%f\r", 'foo') - self.assertRaises(ValueError, locale.format, "%f\r\n", 'foo') - self.assertRaises(ValueError, locale.format, " %f", 'foo') - self.assertRaises(ValueError, locale.format, "%fg", 'foo') - self.assertRaises(ValueError, locale.format, "%^g", 'foo') - self.assertRaises(ValueError, locale.format, "%f%%", 'foo') + self._test_format_string("total=%i%%", 100, out='total=100%') + self._test_format_string("newline: %i\n", 3, out='newline: 3\n') + self._test_format_string("extra: %ii", 3, out='extra: 3i') class TestLocaleFormatString(unittest.TestCase): @@ -292,45 +268,45 @@ class TestCNumberFormatting(CCookedTest, BaseFormattingTest): # Test number formatting with a cooked "C" locale. def test_grouping(self): - self._test_format("%.2f", 12345.67, grouping=True, out='12345.67') + self._test_format_string("%.2f", 12345.67, grouping=True, out='12345.67') def test_grouping_and_padding(self): - self._test_format("%9.2f", 12345.67, grouping=True, out=' 12345.67') + self._test_format_string("%9.2f", 12345.67, grouping=True, out=' 12345.67') class TestFrFRNumberFormatting(FrFRCookedTest, BaseFormattingTest): # Test number formatting with a cooked "fr_FR" locale. def test_decimal_point(self): - self._test_format("%.2f", 12345.67, out='12345,67') + self._test_format_string("%.2f", 12345.67, out='12345,67') def test_grouping(self): - self._test_format("%.2f", 345.67, grouping=True, out='345,67') - self._test_format("%.2f", 12345.67, grouping=True, out='12 345,67') + self._test_format_string("%.2f", 345.67, grouping=True, out='345,67') + self._test_format_string("%.2f", 12345.67, grouping=True, out='12 345,67') def test_grouping_and_padding(self): - self._test_format("%6.2f", 345.67, grouping=True, out='345,67') - self._test_format("%7.2f", 345.67, grouping=True, out=' 345,67') - self._test_format("%8.2f", 12345.67, grouping=True, out='12 345,67') - self._test_format("%9.2f", 12345.67, grouping=True, out='12 345,67') - self._test_format("%10.2f", 12345.67, grouping=True, out=' 12 345,67') - self._test_format("%-6.2f", 345.67, grouping=True, out='345,67') - self._test_format("%-7.2f", 345.67, grouping=True, out='345,67 ') - self._test_format("%-8.2f", 12345.67, grouping=True, out='12 345,67') - self._test_format("%-9.2f", 12345.67, grouping=True, out='12 345,67') - self._test_format("%-10.2f", 12345.67, grouping=True, out='12 345,67 ') + self._test_format_string("%6.2f", 345.67, grouping=True, out='345,67') + self._test_format_string("%7.2f", 345.67, grouping=True, out=' 345,67') + self._test_format_string("%8.2f", 12345.67, grouping=True, out='12 345,67') + self._test_format_string("%9.2f", 12345.67, grouping=True, out='12 345,67') + self._test_format_string("%10.2f", 12345.67, grouping=True, out=' 12 345,67') + self._test_format_string("%-6.2f", 345.67, grouping=True, out='345,67') + self._test_format_string("%-7.2f", 345.67, grouping=True, out='345,67 ') + self._test_format_string("%-8.2f", 12345.67, grouping=True, out='12 345,67') + self._test_format_string("%-9.2f", 12345.67, grouping=True, out='12 345,67') + self._test_format_string("%-10.2f", 12345.67, grouping=True, out='12 345,67 ') def test_integer_grouping(self): - self._test_format("%d", 200, grouping=True, out='200') - self._test_format("%d", 4200, grouping=True, out='4 200') + self._test_format_string("%d", 200, grouping=True, out='200') + self._test_format_string("%d", 4200, grouping=True, out='4 200') def test_integer_grouping_and_padding(self): - self._test_format("%4d", 4200, grouping=True, out='4 200') - self._test_format("%5d", 4200, grouping=True, out='4 200') - self._test_format("%10d", 4200, grouping=True, out='4 200'.rjust(10)) - self._test_format("%-4d", 4200, grouping=True, out='4 200') - self._test_format("%-5d", 4200, grouping=True, out='4 200') - self._test_format("%-10d", 4200, grouping=True, out='4 200'.ljust(10)) + self._test_format_string("%4d", 4200, grouping=True, out='4 200') + self._test_format_string("%5d", 4200, grouping=True, out='4 200') + self._test_format_string("%10d", 4200, grouping=True, out='4 200'.rjust(10)) + self._test_format_string("%-4d", 4200, grouping=True, out='4 200') + self._test_format_string("%-5d", 4200, grouping=True, out='4 200') + self._test_format_string("%-10d", 4200, grouping=True, out='4 200'.ljust(10)) def test_currency(self): euro = '\u20ac' From f682d184fbe805ab40b45c6b4160e58dc493acf1 Mon Sep 17 00:00:00 2001 From: NakanoMiku39 Date: Wed, 8 Nov 2023 20:18:46 +0800 Subject: [PATCH 2/9] Update Cargo.lock --- Cargo.lock | 209 ++++++++++++----------------------------------------- 1 file changed, 48 insertions(+), 161 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8688266ad1..c0c59f1552 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" dependencies = [ "cfg-if", - "getrandom 0.2.8", + "getrandom", "once_cell", "version_check", ] @@ -142,17 +142,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ - "digest 0.10.6", -] - -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "block-padding", - "generic-array", + "digest", ] [[package]] @@ -164,12 +154,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "bstr" version = "0.2.17" @@ -655,22 +639,13 @@ dependencies = [ "syn 1.0.107", ] -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - [[package]] name = "digest" version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ - "block-buffer 0.10.3", + "block-buffer", "crypto-common", "subtle", ] @@ -909,17 +884,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.8" @@ -929,7 +893,7 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "wasm-bindgen", ] @@ -1064,15 +1028,6 @@ dependencies = [ "syn 2.0.32", ] -[[package]] -name = "itertools" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.10.5" @@ -1281,9 +1236,9 @@ dependencies = [ [[package]] name = "malachite" -version = "0.3.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6cf7f4730c30071ba374fac86ad35b1cb7a0716f774737768667ea3fa1828e3" +checksum = "220cb36c52aa6eff45559df497abe0e2a4c1209f92279a746a399f622d7b95c7" dependencies = [ "malachite-base", "malachite-nz", @@ -1292,22 +1247,19 @@ dependencies = [ [[package]] name = "malachite-base" -version = "0.3.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b06bfa98a4b4802af5a4263b4ad4660e28e51e8490f6354eb9336c70767e1c5" +checksum = "6538136c5daf04126d6be4899f7fe4879b7f8de896dd1b4210fe6de5b94f2555" dependencies = [ - "itertools 0.9.0", - "rand 0.7.3", - "rand_chacha 0.2.2", + "itertools 0.11.0", "ryu", - "sha3 0.9.1", ] [[package]] name = "malachite-bigint" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a5110aee54537b0cef214efbebdd7df79b7408db8eef4f6a4b6db9d0d8fc01b" +checksum = "76c3eca3b5df299486144c8423c45c24bdf9e82e2452c8a1eeda547c4d8b5d41" dependencies = [ "derive_more", "malachite", @@ -1318,22 +1270,22 @@ dependencies = [ [[package]] name = "malachite-nz" -version = "0.3.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89e21c64b7af5be3dc8cef16f786243faf59459fe4ba93b44efdeb264e5ade4" +checksum = "5f0b05577b7a3f09433106460b10304f97fc572f0baabf6640e6cb1e23f5fc52" dependencies = [ "embed-doc-image", - "itertools 0.9.0", + "itertools 0.11.0", "malachite-base", ] [[package]] name = "malachite-q" -version = "0.3.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3755e541d5134b5016594c9043094172c4dda9259b3ce824a7b8101941850360" +checksum = "a1cfdb4016292e6acd832eaee261175f3af8bbee62afeefe4420ebce4c440cb5" dependencies = [ - "itertools 0.9.0", + "itertools 0.11.0", "malachite-base", "malachite-nz", ] @@ -1356,7 +1308,7 @@ version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" dependencies = [ - "digest 0.10.6", + "digest", ] [[package]] @@ -1407,7 +1359,7 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12ca7f22ed370d5991a9caec16a83187e865bc8a532f889670337d5a5689e3a1" dependencies = [ - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -1526,12 +1478,6 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "openssl" version = "0.10.55" @@ -1657,7 +1603,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf" dependencies = [ "phf_shared", - "rand 0.8.5", + "rand", ] [[package]] @@ -1758,9 +1704,9 @@ dependencies = [ [[package]] name = "puruspe" -version = "0.1.5" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b7e158a385023d209d6d5f2585c4b468f6dcb3dd5aca9b75c4f1678c05bb375" +checksum = "fe7765e19fb2ba6fd4373b8d90399f5321683ea7c11b598c6bbaa3a72e9c83b8" [[package]] name = "python3-sys" @@ -1797,19 +1743,6 @@ dependencies = [ "nibble_vec", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc", -] - [[package]] name = "rand" version = "0.8.5" @@ -1817,18 +1750,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", + "rand_chacha", + "rand_core", ] [[package]] @@ -1838,16 +1761,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", + "rand_core", ] [[package]] @@ -1856,16 +1770,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.8", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", + "getrandom", ] [[package]] @@ -1911,7 +1816,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.8", + "getrandom", "redox_syscall 0.2.16", "thiserror", ] @@ -2041,7 +1946,7 @@ dependencies = [ [[package]] name = "rustpython-ast" version = "0.3.1" -source = "git+https://github.com/RustPython/Parser.git?rev=13cae0af64d0a23de95f08c0210e97ad74d155e9#13cae0af64d0a23de95f08c0210e97ad74d155e9" +source = "git+https://github.com/RustPython/Parser.git?rev=52edf4525ec300f2b69670f3991784bbcf140564#52edf4525ec300f2b69670f3991784bbcf140564" dependencies = [ "is-macro", "malachite-bigint", @@ -2087,7 +1992,7 @@ dependencies = [ "once_cell", "parking_lot", "radium", - "rand 0.8.5", + "rand", "rustpython-format", "siphasher", "volatile", @@ -2153,7 +2058,7 @@ dependencies = [ [[package]] name = "rustpython-format" version = "0.3.1" -source = "git+https://github.com/RustPython/Parser.git?rev=13cae0af64d0a23de95f08c0210e97ad74d155e9#13cae0af64d0a23de95f08c0210e97ad74d155e9" +source = "git+https://github.com/RustPython/Parser.git?rev=52edf4525ec300f2b69670f3991784bbcf140564#52edf4525ec300f2b69670f3991784bbcf140564" dependencies = [ "bitflags 2.4.0", "itertools 0.11.0", @@ -2180,7 +2085,7 @@ dependencies = [ [[package]] name = "rustpython-literal" version = "0.3.1" -source = "git+https://github.com/RustPython/Parser.git?rev=13cae0af64d0a23de95f08c0210e97ad74d155e9#13cae0af64d0a23de95f08c0210e97ad74d155e9" +source = "git+https://github.com/RustPython/Parser.git?rev=52edf4525ec300f2b69670f3991784bbcf140564#52edf4525ec300f2b69670f3991784bbcf140564" dependencies = [ "hexf-parse", "is-macro", @@ -2192,7 +2097,7 @@ dependencies = [ [[package]] name = "rustpython-parser" version = "0.3.1" -source = "git+https://github.com/RustPython/Parser.git?rev=13cae0af64d0a23de95f08c0210e97ad74d155e9#13cae0af64d0a23de95f08c0210e97ad74d155e9" +source = "git+https://github.com/RustPython/Parser.git?rev=52edf4525ec300f2b69670f3991784bbcf140564#52edf4525ec300f2b69670f3991784bbcf140564" dependencies = [ "anyhow", "is-macro", @@ -2215,7 +2120,7 @@ dependencies = [ [[package]] name = "rustpython-parser-core" version = "0.3.1" -source = "git+https://github.com/RustPython/Parser.git?rev=13cae0af64d0a23de95f08c0210e97ad74d155e9#13cae0af64d0a23de95f08c0210e97ad74d155e9" +source = "git+https://github.com/RustPython/Parser.git?rev=52edf4525ec300f2b69670f3991784bbcf140564#52edf4525ec300f2b69670f3991784bbcf140564" dependencies = [ "is-macro", "memchr", @@ -2225,7 +2130,7 @@ dependencies = [ [[package]] name = "rustpython-parser-vendored" version = "0.3.1" -source = "git+https://github.com/RustPython/Parser.git?rev=13cae0af64d0a23de95f08c0210e97ad74d155e9#13cae0af64d0a23de95f08c0210e97ad74d155e9" +source = "git+https://github.com/RustPython/Parser.git?rev=52edf4525ec300f2b69670f3991784bbcf140564#52edf4525ec300f2b69670f3991784bbcf140564" dependencies = [ "memchr", "once_cell", @@ -2254,7 +2159,7 @@ dependencies = [ "crc32fast", "crossbeam-utils", "csv-core", - "digest 0.10.6", + "digest", "dns-lookup", "dyn-clone", "flate2", @@ -2284,15 +2189,15 @@ dependencies = [ "parking_lot", "paste", "puruspe", - "rand 0.8.5", - "rand_core 0.6.4", + "rand", + "rand_core", "rustpython-common", "rustpython-derive", "rustpython-vm", "schannel", "sha-1", "sha2", - "sha3 0.10.6", + "sha3", "socket2", "system-configuration", "termios", @@ -2327,7 +2232,7 @@ dependencies = [ "exitcode", "flame", "flamer", - "getrandom 0.2.8", + "getrandom", "glob", "half", "hex", @@ -2349,7 +2254,7 @@ dependencies = [ "optional", "parking_lot", "paste", - "rand 0.8.5", + "rand", "result-like", "rustc_version", "rustpython-ast", @@ -2437,9 +2342,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.12" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "same-file" @@ -2538,7 +2443,7 @@ checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.6", + "digest", ] [[package]] @@ -2549,19 +2454,7 @@ checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.6", -] - -[[package]] -name = "sha3" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" -dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", - "keccak", - "opaque-debug", + "digest", ] [[package]] @@ -2570,7 +2463,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" dependencies = [ - "digest 0.10.6", + "digest", "keccak", ] @@ -3066,7 +2959,7 @@ dependencies = [ "getopts", "log", "phf_codegen", - "rand 0.8.5", + "rand", "time", ] @@ -3083,8 +2976,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" dependencies = [ "atomic", - "getrandom 0.2.8", - "rand 0.8.5", + "getrandom", + "rand", "uuid-macro-internal", ] @@ -3134,12 +3027,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" From 99d992f70808e2c8e686f4a0d92926d4431ab5a4 Mon Sep 17 00:00:00 2001 From: NakanoMiku39 Date: Wed, 8 Nov 2023 20:41:23 +0800 Subject: [PATCH 3/9] Update test_atexit.py from CPython v3.12 --- Lib/test/test_atexit.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py index 7ac063cfc7..913b7556be 100644 --- a/Lib/test/test_atexit.py +++ b/Lib/test/test_atexit.py @@ -1,6 +1,5 @@ import atexit import os -import sys import textwrap import unittest from test import support From b5e21ab136ddedfb94aad34ab9d043afc4ceef1e Mon Sep 17 00:00:00 2001 From: NakanoMiku39 Date: Thu, 9 Nov 2023 14:59:59 +0800 Subject: [PATCH 4/9] Add Lib/test/test_opcodes.py cpython version: 3.12 --- Lib/test/test_opcodes.py | 138 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 Lib/test/test_opcodes.py diff --git a/Lib/test/test_opcodes.py b/Lib/test/test_opcodes.py new file mode 100644 index 0000000000..72488b2bb6 --- /dev/null +++ b/Lib/test/test_opcodes.py @@ -0,0 +1,138 @@ +# Python test set -- part 2, opcodes + +import unittest +from test import support +from test.typinganndata import ann_module + +class OpcodeTest(unittest.TestCase): + + def test_try_inside_for_loop(self): + n = 0 + for i in range(10): + n = n+i + try: 1/0 + except NameError: pass + except ZeroDivisionError: pass + except TypeError: pass + try: pass + except: pass + try: pass + finally: pass + n = n+i + if n != 90: + self.fail('try inside for') + + def test_setup_annotations_line(self): + # check that SETUP_ANNOTATIONS does not create spurious line numbers + try: + with open(ann_module.__file__, encoding="utf-8") as f: + txt = f.read() + co = compile(txt, ann_module.__file__, 'exec') + self.assertEqual(co.co_firstlineno, 1) + except OSError: + pass + + def test_default_annotations_exist(self): + class C: pass + self.assertEqual(C.__annotations__, {}) + + def test_use_existing_annotations(self): + ns = {'__annotations__': {1: 2}} + exec('x: int', ns) + self.assertEqual(ns['__annotations__'], {'x': int, 1: 2}) + + def test_do_not_recreate_annotations(self): + # Don't rely on the existence of the '__annotations__' global. + with support.swap_item(globals(), '__annotations__', {}): + del globals()['__annotations__'] + class C: + del __annotations__ + with self.assertRaises(NameError): + x: int + + def test_raise_class_exceptions(self): + + class AClass(Exception): pass + class BClass(AClass): pass + class CClass(Exception): pass + class DClass(AClass): + def __init__(self, ignore): + pass + + try: raise AClass() + except: pass + + try: raise AClass() + except AClass: pass + + try: raise BClass() + except AClass: pass + + try: raise BClass() + except CClass: self.fail() + except: pass + + a = AClass() + b = BClass() + + try: + raise b + except AClass as v: + self.assertEqual(v, b) + else: + self.fail("no exception") + + # not enough arguments + ##try: raise BClass, a + ##except TypeError: pass + ##else: self.fail("no exception") + + try: raise DClass(a) + except DClass as v: + self.assertIsInstance(v, DClass) + else: + self.fail("no exception") + + def test_compare_function_objects(self): + + f = eval('lambda: None') + g = eval('lambda: None') + self.assertNotEqual(f, g) + + f = eval('lambda a: a') + g = eval('lambda a: a') + self.assertNotEqual(f, g) + + f = eval('lambda a=1: a') + g = eval('lambda a=1: a') + self.assertNotEqual(f, g) + + f = eval('lambda: 0') + g = eval('lambda: 1') + self.assertNotEqual(f, g) + + f = eval('lambda: None') + g = eval('lambda a: None') + self.assertNotEqual(f, g) + + f = eval('lambda a: None') + g = eval('lambda b: None') + self.assertNotEqual(f, g) + + f = eval('lambda a: None') + g = eval('lambda a=None: None') + self.assertNotEqual(f, g) + + f = eval('lambda a=0: None') + g = eval('lambda a=1: None') + self.assertNotEqual(f, g) + + def test_modulo_of_string_subclasses(self): + class MyString(str): + def __mod__(self, value): + return 42 + self.assertEqual(MyString() % 3, 42) + + +if __name__ == '__main__': + unittest.main() From 06b9b4938d381f67fb36cf5d7c1d9ffbda007100 Mon Sep 17 00:00:00 2001 From: NakanoMiku39 Date: Thu, 9 Nov 2023 15:05:04 +0800 Subject: [PATCH 5/9] Add Lib/test/typinganndata folder cpython version: 3.12 --- Lib/test/typinganndata/__init__.py | 0 Lib/test/typinganndata/ann_module.py | 62 +++++++++++++++++++++++++++ Lib/test/typinganndata/ann_module2.py | 36 ++++++++++++++++ Lib/test/typinganndata/ann_module3.py | 18 ++++++++ Lib/test/typinganndata/ann_module4.py | 5 +++ Lib/test/typinganndata/ann_module5.py | 10 +++++ Lib/test/typinganndata/ann_module6.py | 7 +++ Lib/test/typinganndata/ann_module7.py | 11 +++++ Lib/test/typinganndata/ann_module8.py | 10 +++++ Lib/test/typinganndata/ann_module9.py | 14 ++++++ 10 files changed, 173 insertions(+) create mode 100644 Lib/test/typinganndata/__init__.py create mode 100644 Lib/test/typinganndata/ann_module.py create mode 100644 Lib/test/typinganndata/ann_module2.py create mode 100644 Lib/test/typinganndata/ann_module3.py create mode 100644 Lib/test/typinganndata/ann_module4.py create mode 100644 Lib/test/typinganndata/ann_module5.py create mode 100644 Lib/test/typinganndata/ann_module6.py create mode 100644 Lib/test/typinganndata/ann_module7.py create mode 100644 Lib/test/typinganndata/ann_module8.py create mode 100644 Lib/test/typinganndata/ann_module9.py diff --git a/Lib/test/typinganndata/__init__.py b/Lib/test/typinganndata/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Lib/test/typinganndata/ann_module.py b/Lib/test/typinganndata/ann_module.py new file mode 100644 index 0000000000..5081e6b583 --- /dev/null +++ b/Lib/test/typinganndata/ann_module.py @@ -0,0 +1,62 @@ + + +""" +The module for testing variable annotations. +Empty lines above are for good reason (testing for correct line numbers) +""" + +from typing import Optional +from functools import wraps + +__annotations__[1] = 2 + +class C: + + x = 5; y: Optional['C'] = None + +from typing import Tuple +x: int = 5; y: str = x; f: Tuple[int, int] + +class M(type): + + __annotations__['123'] = 123 + o: type = object + +(pars): bool = True + +class D(C): + j: str = 'hi'; k: str= 'bye' + +from types import new_class +h_class = new_class('H', (C,)) +j_class = new_class('J') + +class F(): + z: int = 5 + def __init__(self, x): + pass + +class Y(F): + def __init__(self): + super(F, self).__init__(123) + +class Meta(type): + def __new__(meta, name, bases, namespace): + return super().__new__(meta, name, bases, namespace) + +class S(metaclass = Meta): + x: str = 'something' + y: str = 'something else' + +def foo(x: int = 10): + def bar(y: List[str]): + x: str = 'yes' + bar() + +def dec(func): + @wraps(func) + def wrapper(*args, **kwargs): + return func(*args, **kwargs) + return wrapper + +u: int | float diff --git a/Lib/test/typinganndata/ann_module2.py b/Lib/test/typinganndata/ann_module2.py new file mode 100644 index 0000000000..76cf5b3ad9 --- /dev/null +++ b/Lib/test/typinganndata/ann_module2.py @@ -0,0 +1,36 @@ +""" +Some correct syntax for variable annotation here. +More examples are in test_grammar and test_parser. +""" + +from typing import no_type_check, ClassVar + +i: int = 1 +j: int +x: float = i/10 + +def f(): + class C: ... + return C() + +f().new_attr: object = object() + +class C: + def __init__(self, x: int) -> None: + self.x = x + +c = C(5) +c.new_attr: int = 10 + +__annotations__ = {} + + +@no_type_check +class NTC: + def meth(self, param: complex) -> None: + ... + +class CV: + var: ClassVar['CV'] + +CV.var = CV() diff --git a/Lib/test/typinganndata/ann_module3.py b/Lib/test/typinganndata/ann_module3.py new file mode 100644 index 0000000000..eccd7be22d --- /dev/null +++ b/Lib/test/typinganndata/ann_module3.py @@ -0,0 +1,18 @@ +""" +Correct syntax for variable annotation that should fail at runtime +in a certain manner. More examples are in test_grammar and test_parser. +""" + +def f_bad_ann(): + __annotations__[1] = 2 + +class C_OK: + def __init__(self, x: int) -> None: + self.x: no_such_name = x # This one is OK as proposed by Guido + +class D_bad_ann: + def __init__(self, x: int) -> None: + sfel.y: int = 0 + +def g_bad_ann(): + no_such_name.attr: int = 0 diff --git a/Lib/test/typinganndata/ann_module4.py b/Lib/test/typinganndata/ann_module4.py new file mode 100644 index 0000000000..13e9aee54c --- /dev/null +++ b/Lib/test/typinganndata/ann_module4.py @@ -0,0 +1,5 @@ +# This ann_module isn't for test_typing, +# it's for test_module + +a:int=3 +b:str=4 diff --git a/Lib/test/typinganndata/ann_module5.py b/Lib/test/typinganndata/ann_module5.py new file mode 100644 index 0000000000..837041e121 --- /dev/null +++ b/Lib/test/typinganndata/ann_module5.py @@ -0,0 +1,10 @@ +# Used by test_typing to verify that Final wrapped in ForwardRef works. + +from __future__ import annotations + +from typing import Final + +name: Final[str] = "final" + +class MyClass: + value: Final = 3000 diff --git a/Lib/test/typinganndata/ann_module6.py b/Lib/test/typinganndata/ann_module6.py new file mode 100644 index 0000000000..679175669b --- /dev/null +++ b/Lib/test/typinganndata/ann_module6.py @@ -0,0 +1,7 @@ +# Tests that top-level ClassVar is not allowed + +from __future__ import annotations + +from typing import ClassVar + +wrong: ClassVar[int] = 1 diff --git a/Lib/test/typinganndata/ann_module7.py b/Lib/test/typinganndata/ann_module7.py new file mode 100644 index 0000000000..8f890cd280 --- /dev/null +++ b/Lib/test/typinganndata/ann_module7.py @@ -0,0 +1,11 @@ +# Tests class have ``__text_signature__`` + +from __future__ import annotations + +DEFAULT_BUFFER_SIZE = 8192 + +class BufferedReader(object): + """BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n--\n\n + Create a new buffered reader using the given readable raw IO object. + """ + pass diff --git a/Lib/test/typinganndata/ann_module8.py b/Lib/test/typinganndata/ann_module8.py new file mode 100644 index 0000000000..bd03148137 --- /dev/null +++ b/Lib/test/typinganndata/ann_module8.py @@ -0,0 +1,10 @@ +# Test `@no_type_check`, +# see https://bugs.python.org/issue46571 + +class NoTypeCheck_Outer: + class Inner: + x: int + + +def NoTypeCheck_function(arg: int) -> int: + ... diff --git a/Lib/test/typinganndata/ann_module9.py b/Lib/test/typinganndata/ann_module9.py new file mode 100644 index 0000000000..952217393e --- /dev/null +++ b/Lib/test/typinganndata/ann_module9.py @@ -0,0 +1,14 @@ +# Test ``inspect.formatannotation`` +# https://github.com/python/cpython/issues/96073 + +from typing import Union, List + +ann = Union[List[str], int] + +# mock typing._type_repr behaviour +class A: ... + +A.__module__ = 'testModule.typing' +A.__qualname__ = 'A' + +ann1 = Union[List[A], int] From a96926cd770d2785c472ba11e000be511daffc82 Mon Sep 17 00:00:00 2001 From: NakanoMiku39 Date: Thu, 9 Nov 2023 15:06:08 +0800 Subject: [PATCH 6/9] Remove Lib/test/test_opcode.py This file is a duplicate of test_codeop.py with a few changes --- Lib/test/test_opcode.py | 356 ---------------------------------------- 1 file changed, 356 deletions(-) delete mode 100644 Lib/test/test_opcode.py diff --git a/Lib/test/test_opcode.py b/Lib/test/test_opcode.py deleted file mode 100644 index 170eb1cb1d..0000000000 --- a/Lib/test/test_opcode.py +++ /dev/null @@ -1,356 +0,0 @@ -""" - Test cases for codeop.py - Nick Mathewson -""" -import sys -import unittest -import warnings -from test import support -from test.support import warnings_helper - -from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT -import io - -if support.is_jython: - - def unify_callables(d): - for n,v in d.items(): - if hasattr(v, '__call__'): - d[n] = True - return d - -class CodeopTests(unittest.TestCase): - - def assertValid(self, str, symbol='single'): - '''succeed iff str is a valid piece of code''' - if support.is_jython: - code = compile_command(str, "", symbol) - self.assertTrue(code) - if symbol == "single": - d,r = {},{} - saved_stdout = sys.stdout - sys.stdout = io.StringIO() - try: - exec(code, d) - exec(compile(str,"","single"), r) - finally: - sys.stdout = saved_stdout - elif symbol == 'eval': - ctx = {'a': 2} - d = { 'value': eval(code,ctx) } - r = { 'value': eval(str,ctx) } - self.assertEqual(unify_callables(r),unify_callables(d)) - else: - expected = compile(str, "", symbol, PyCF_DONT_IMPLY_DEDENT) - self.assertEqual(compile_command(str, "", symbol), expected) - - def assertIncomplete(self, str, symbol='single'): - '''succeed iff str is the start of a valid piece of code''' - self.assertEqual(compile_command(str, symbol=symbol), None) - - def assertInvalid(self, str, symbol='single', is_syntax=1): - '''succeed iff str is the start of an invalid piece of code''' - try: - compile_command(str,symbol=symbol) - self.fail("No exception raised for invalid code") - except SyntaxError: - self.assertTrue(is_syntax) - except OverflowError: - self.assertTrue(not is_syntax) - - # TODO: RUSTPYTHON - @unittest.expectedFailure - def test_valid(self): - av = self.assertValid - - # special case - if not support.is_jython: - self.assertEqual(compile_command(""), - compile("pass", "", 'single', - PyCF_DONT_IMPLY_DEDENT)) - self.assertEqual(compile_command("\n"), - compile("pass", "", 'single', - PyCF_DONT_IMPLY_DEDENT)) - else: - av("") - av("\n") - - av("a = 1") - av("\na = 1") - av("a = 1\n") - av("a = 1\n\n") - av("\n\na = 1\n\n") - - av("def x():\n pass\n") - av("if 1:\n pass\n") - - av("\n\nif 1: pass\n") - av("\n\nif 1: pass\n\n") - - av("def x():\n\n pass\n") - av("def x():\n pass\n \n") - av("def x():\n pass\n \n") - - av("pass\n") - av("3**3\n") - - av("if 9==3:\n pass\nelse:\n pass\n") - av("if 1:\n pass\n if 1:\n pass\n else:\n pass\n") - - av("#a\n#b\na = 3\n") - av("#a\n\n \na=3\n") - av("a=3\n\n") - av("a = 9+ \\\n3") - - av("3**3","eval") - av("(lambda z: \n z**3)","eval") - - av("9+ \\\n3","eval") - av("9+ \\\n3\n","eval") - - av("\n\na**3","eval") - av("\n \na**3","eval") - av("#a\n#b\na**3","eval") - - av("\n\na = 1\n\n") - av("\n\nif 1: a=1\n\n") - - av("if 1:\n pass\n if 1:\n pass\n else:\n pass\n") - av("#a\n\n \na=3\n\n") - - av("\n\na**3","eval") - av("\n \na**3","eval") - av("#a\n#b\na**3","eval") - - av("def f():\n try: pass\n finally: [x for x in (1,2)]\n") - av("def f():\n pass\n#foo\n") - av("@a.b.c\ndef f():\n pass\n") - - # TODO: RUSTPYTHON - @unittest.expectedFailure - def test_incomplete(self): - ai = self.assertIncomplete - - ai("(a **") - ai("(a,b,") - ai("(a,b,(") - ai("(a,b,(") - ai("a = (") - ai("a = {") - ai("b + {") - - ai("print([1,\n2,") - ai("print({1:1,\n2:3,") - ai("print((1,\n2,") - - ai("if 9==3:\n pass\nelse:") - ai("if 9==3:\n pass\nelse:\n") - ai("if 9==3:\n pass\nelse:\n pass") - ai("if 1:") - ai("if 1:\n") - ai("if 1:\n pass\n if 1:\n pass\n else:") - ai("if 1:\n pass\n if 1:\n pass\n else:\n") - ai("if 1:\n pass\n if 1:\n pass\n else:\n pass") - - ai("def x():") - ai("def x():\n") - ai("def x():\n\n") - - ai("def x():\n pass") - ai("def x():\n pass\n ") - ai("def x():\n pass\n ") - ai("\n\ndef x():\n pass") - - ai("a = 9+ \\") - ai("a = 'a\\") - ai("a = '''xy") - - ai("","eval") - ai("\n","eval") - ai("(","eval") - ai("(9+","eval") - ai("9+ \\","eval") - ai("lambda z: \\","eval") - - ai("if True:\n if True:\n if True: \n") - - ai("@a(") - ai("@a(b") - ai("@a(b,") - ai("@a(b,c") - ai("@a(b,c,") - - ai("from a import (") - ai("from a import (b") - ai("from a import (b,") - ai("from a import (b,c") - ai("from a import (b,c,") - - ai("[") - ai("[a") - ai("[a,") - ai("[a,b") - ai("[a,b,") - - ai("{") - ai("{a") - ai("{a:") - ai("{a:b") - ai("{a:b,") - ai("{a:b,c") - ai("{a:b,c:") - ai("{a:b,c:d") - ai("{a:b,c:d,") - - ai("a(") - ai("a(b") - ai("a(b,") - ai("a(b,c") - ai("a(b,c,") - - ai("a[") - ai("a[b") - ai("a[b,") - ai("a[b:") - ai("a[b:c") - ai("a[b:c:") - ai("a[b:c:d") - - ai("def a(") - ai("def a(b") - ai("def a(b,") - ai("def a(b,c") - ai("def a(b,c,") - - ai("(") - ai("(a") - ai("(a,") - ai("(a,b") - ai("(a,b,") - - ai("if a:\n pass\nelif b:") - ai("if a:\n pass\nelif b:\n pass\nelse:") - - ai("while a:") - ai("while a:\n pass\nelse:") - - ai("for a in b:") - ai("for a in b:\n pass\nelse:") - - ai("try:") - ai("try:\n pass\nexcept:") - ai("try:\n pass\nfinally:") - ai("try:\n pass\nexcept:\n pass\nfinally:") - - ai("with a:") - ai("with a as b:") - - ai("class a:") - ai("class a(") - ai("class a(b") - ai("class a(b,") - ai("class a():") - - ai("[x for") - ai("[x for x in") - ai("[x for x in (") - - ai("(x for") - ai("(x for x in") - ai("(x for x in (") - - def test_invalid(self): - ai = self.assertInvalid - ai("a b") - - ai("a @") - ai("a b @") - ai("a ** @") - - ai("a = ") - ai("a = 9 +") - - ai("def x():\n\npass\n") - - ai("\n\n if 1: pass\n\npass") - - ai("a = 9+ \\\n") - ai("a = 'a\\ ") - ai("a = 'a\\\n") - - ai("a = 1","eval") - ai("]","eval") - ai("())","eval") - ai("[}","eval") - ai("9+","eval") - ai("lambda z:","eval") - ai("a b","eval") - - ai("return 2.3") - ai("if (a == 1 and b = 2): pass") - - ai("del 1") - ai("del (1,)") - ai("del [1]") - ai("del '1'") - - ai("[i for i in range(10)] = (1, 2, 3)") - - def test_invalid_exec(self): - ai = self.assertInvalid - ai("raise = 4", symbol="exec") - ai('def a-b', symbol='exec') - ai('await?', symbol='exec') - ai('=!=', symbol='exec') - ai('a await raise b', symbol='exec') - ai('a await raise b?+1', symbol='exec') - - def test_filename(self): - self.assertEqual(compile_command("a = 1\n", "abc").co_filename, - compile("a = 1\n", "abc", 'single').co_filename) - self.assertNotEqual(compile_command("a = 1\n", "abc").co_filename, - compile("a = 1\n", "def", 'single').co_filename) - - # TODO: RUSTPYTHON - @unittest.expectedFailure - def test_warning(self): - # Test that the warning is only returned once. - with warnings_helper.check_warnings( - (".*literal", SyntaxWarning), - (".*invalid", DeprecationWarning), - ) as w: - compile_command(r"'\e' is 0") - self.assertEqual(len(w.warnings), 2) - - # bpo-41520: check SyntaxWarning treated as an SyntaxError - with warnings.catch_warnings(), self.assertRaises(SyntaxError): - warnings.simplefilter('error', SyntaxWarning) - compile_command('1 is 1', symbol='exec') - - # Check DeprecationWarning treated as an SyntaxError - with warnings.catch_warnings(), self.assertRaises(SyntaxError): - warnings.simplefilter('error', DeprecationWarning) - compile_command(r"'\e'", symbol='exec') - - # TODO: RUSTPYTHON - @unittest.expectedFailure - def test_incomplete_warning(self): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') - self.assertIncomplete("'\\e' + (") - self.assertEqual(w, []) - - # TODO: RUSTPYTHON - @unittest.expectedFailure - def test_invalid_warning(self): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') - self.assertInvalid("'\\e' 1") - self.assertEqual(len(w), 1) - self.assertEqual(w[0].category, DeprecationWarning) - self.assertRegex(str(w[0].message), 'invalid escape sequence') - self.assertEqual(w[0].filename, '') - - -if __name__ == "__main__": - unittest.main() From 8ff0872d41c3692435e3bce37db8cf2fd4ffb345 Mon Sep 17 00:00:00 2001 From: NakanoMiku39 Date: Thu, 9 Nov 2023 15:11:35 +0800 Subject: [PATCH 7/9] Update test_codeop.py from CPython v3.12 --- Lib/test/test_codeop.py | 149 ++++++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 75 deletions(-) diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py index 671148ce2b..f39f51e824 100644 --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -2,48 +2,19 @@ Test cases for codeop.py Nick Mathewson """ -import sys import unittest import warnings -from test import support from test.support import warnings_helper +from textwrap import dedent from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT -import io - -if support.is_jython: - - def unify_callables(d): - for n, v in d.items(): - if hasattr(v, '__call__'): - d[n] = True - return d - class CodeopTests(unittest.TestCase): def assertValid(self, str, symbol='single'): '''succeed iff str is a valid piece of code''' - if support.is_jython: - code = compile_command(str, "", symbol) - self.assertTrue(code) - if symbol == "single": - d, r = {}, {} - saved_stdout = sys.stdout - sys.stdout = io.StringIO() - try: - exec(code, d) - exec(compile(str, "", "single"), r) - finally: - sys.stdout = saved_stdout - elif symbol == 'eval': - ctx = {'a': 2} - d = {'value': eval(code, ctx)} - r = {'value': eval(str, ctx)} - self.assertEqual(unify_callables(r), unify_callables(d)) - else: - expected = compile(str, "", symbol, PyCF_DONT_IMPLY_DEDENT) - self.assertEqual(compile_command(str, "", symbol), expected) + expected = compile(str, "", symbol, PyCF_DONT_IMPLY_DEDENT) + self.assertEqual(compile_command(str, "", symbol), expected) def assertIncomplete(self, str, symbol='single'): '''succeed iff str is the start of a valid piece of code''' @@ -52,30 +23,23 @@ def assertIncomplete(self, str, symbol='single'): def assertInvalid(self, str, symbol='single', is_syntax=1): '''succeed iff str is the start of an invalid piece of code''' try: - compile_command(str, symbol=symbol) + compile_command(str,symbol=symbol) self.fail("No exception raised for invalid code") except SyntaxError: self.assertTrue(is_syntax) except OverflowError: self.assertTrue(not is_syntax) - # TODO: RUSTPYTHON - - @unittest.expectedFailure def test_valid(self): av = self.assertValid # special case - if not support.is_jython: - self.assertEqual(compile_command(""), - compile("pass", "", 'single', - PyCF_DONT_IMPLY_DEDENT)) - self.assertEqual(compile_command("\n"), - compile("pass", "", 'single', - PyCF_DONT_IMPLY_DEDENT)) - else: - av("") - av("\n") + self.assertEqual(compile_command(""), + compile("pass", "", 'single', + PyCF_DONT_IMPLY_DEDENT)) + self.assertEqual(compile_command("\n"), + compile("pass", "", 'single', + PyCF_DONT_IMPLY_DEDENT)) av("a = 1") av("\na = 1") @@ -104,15 +68,15 @@ def test_valid(self): av("a=3\n\n") av("a = 9+ \\\n3") - av("3**3", "eval") - av("(lambda z: \n z**3)", "eval") + av("3**3","eval") + av("(lambda z: \n z**3)","eval") - av("9+ \\\n3", "eval") - av("9+ \\\n3\n", "eval") + av("9+ \\\n3","eval") + av("9+ \\\n3\n","eval") - av("\n\na**3", "eval") - av("\n \na**3", "eval") - av("#a\n#b\na**3", "eval") + av("\n\na**3","eval") + av("\n \na**3","eval") + av("#a\n#b\na**3","eval") av("\n\na = 1\n\n") av("\n\nif 1: a=1\n\n") @@ -120,9 +84,9 @@ def test_valid(self): av("if 1:\n pass\n if 1:\n pass\n else:\n pass\n") av("#a\n\n \na=3\n\n") - av("\n\na**3", "eval") - av("\n \na**3", "eval") - av("#a\n#b\na**3", "eval") + av("\n\na**3","eval") + av("\n \na**3","eval") + av("#a\n#b\na**3","eval") av("def f():\n try: pass\n finally: [x for x in (1,2)]\n") av("def f():\n pass\n#foo\n") @@ -141,6 +105,10 @@ def test_incomplete(self): ai("a = {") ai("b + {") + ai("print([1,\n2,") + ai("print({1:1,\n2:3,") + ai("print((1,\n2,") + ai("if 9==3:\n pass\nelse:") ai("if 9==3:\n pass\nelse:\n") ai("if 9==3:\n pass\nelse:\n pass") @@ -163,13 +131,12 @@ def test_incomplete(self): ai("a = 'a\\") ai("a = '''xy") - ai("", "eval") - ai("\n", "eval") - ai("(", "eval") - ai("(\n\n\n", "eval") - ai("(9+", "eval") - ai("9+ \\", "eval") - ai("lambda z: \\", "eval") + ai("","eval") + ai("\n","eval") + ai("(","eval") + ai("(9+","eval") + ai("9+ \\","eval") + ai("lambda z: \\","eval") ai("if True:\n if True:\n if True: \n") @@ -277,14 +244,13 @@ def test_invalid(self): ai("a = 'a\\ ") ai("a = 'a\\\n") - ai("a = 1", "eval") - ai("a = (", "eval") - ai("]", "eval") - ai("())", "eval") - ai("[}", "eval") - ai("9+", "eval") - ai("lambda z:", "eval") - ai("a b", "eval") + ai("a = 1","eval") + ai("]","eval") + ai("())","eval") + ai("[}","eval") + ai("9+","eval") + ai("lambda z:","eval") + ai("a b","eval") ai("return 2.3") ai("if (a == 1 and b = 2): pass") @@ -314,11 +280,11 @@ def test_filename(self): # TODO: RUSTPYTHON @unittest.expectedFailure def test_warning(self): - # Teswarnings_helper.check_warningsonly returned once. + # Test that the warning is only returned once. with warnings_helper.check_warnings( - (".*literal", SyntaxWarning), - (".*invalid", DeprecationWarning), - ) as w: + ('"is" with \'str\' literal', SyntaxWarning), + ("invalid escape sequence", SyntaxWarning), + ) as w: compile_command(r"'\e' is 0") self.assertEqual(len(w.warnings), 2) @@ -327,6 +293,39 @@ def test_warning(self): warnings.simplefilter('error', SyntaxWarning) compile_command('1 is 1', symbol='exec') + # Check SyntaxWarning treated as an SyntaxError + with warnings.catch_warnings(), self.assertRaises(SyntaxError): + warnings.simplefilter('error', SyntaxWarning) + compile_command(r"'\e'", symbol='exec') + + def test_incomplete_warning(self): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + self.assertIncomplete("'\\e' + (") + self.assertEqual(w, []) + + def test_invalid_warning(self): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + self.assertInvalid("'\\e' 1") + self.assertEqual(len(w), 1) + self.assertEqual(w[0].category, SyntaxWarning) + self.assertRegex(str(w[0].message), 'invalid escape sequence') + self.assertEqual(w[0].filename, '') + + def assertSyntaxErrorMatches(self, code, message): + with self.subTest(code): + with self.assertRaisesRegex(SyntaxError, message): + compile_command(code, symbol='exec') + + def test_syntax_errors(self): + self.assertSyntaxErrorMatches( + dedent("""\ + def foo(x,x): + pass + """), "duplicate argument 'x' in function definition") + + if __name__ == "__main__": unittest.main() From 488bac741373b2a7639c9931d5e81c52e7f5b9e4 Mon Sep 17 00:00:00 2001 From: NakanoMiku39 Date: Thu, 9 Nov 2023 15:20:52 +0800 Subject: [PATCH 8/9] Update codeop.py from CPython v3.12 --- Lib/codeop.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Lib/codeop.py b/Lib/codeop.py index 2213b69f23..4dd096574b 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -70,8 +70,7 @@ def _maybe_compile(compiler, source, filename, symbol): return None # fallthrough - return compiler(source, filename, symbol) - + return compiler(source, filename, symbol, incomplete_input=False) def _is_syntax_error(err1, err2): rep1 = repr(err1) @@ -82,8 +81,13 @@ def _is_syntax_error(err1, err2): return True return False -def _compile(source, filename, symbol): - return compile(source, filename, symbol, PyCF_DONT_IMPLY_DEDENT | PyCF_ALLOW_INCOMPLETE_INPUT) +def _compile(source, filename, symbol, incomplete_input=True): + flags = 0 + if incomplete_input: + flags |= PyCF_ALLOW_INCOMPLETE_INPUT + flags |= PyCF_DONT_IMPLY_DEDENT + return compile(source, filename, symbol, flags) + def compile_command(source, filename="", symbol="single"): r"""Compile a command and determine whether it is incomplete. @@ -114,8 +118,12 @@ class Compile: def __init__(self): self.flags = PyCF_DONT_IMPLY_DEDENT | PyCF_ALLOW_INCOMPLETE_INPUT - def __call__(self, source, filename, symbol): - codeob = compile(source, filename, symbol, self.flags, True) + def __call__(self, source, filename, symbol, **kwargs): + flags = self.flags + if kwargs.get('incomplete_input', True) is False: + flags &= ~PyCF_DONT_IMPLY_DEDENT + flags &= ~PyCF_ALLOW_INCOMPLETE_INPUT + codeob = compile(source, filename, symbol, flags, True) for feature in _features: if codeob.co_flags & feature.compiler_flag: self.flags |= feature.compiler_flag From ee9f6ae079ea13b51679b97eaf773b6c04828785 Mon Sep 17 00:00:00 2001 From: NakanoMiku39 Date: Thu, 9 Nov 2023 15:29:35 +0800 Subject: [PATCH 9/9] Edit Lib/test/test_codeop.py cpython version: 3.12 --- Lib/test/test_codeop.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py index f39f51e824..19117fa409 100644 --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -30,6 +30,8 @@ def assertInvalid(self, str, symbol='single', is_syntax=1): except OverflowError: self.assertTrue(not is_syntax) + # TODO: RUSTPYTHON + @unittest.expectedFailure def test_valid(self): av = self.assertValid @@ -298,12 +300,15 @@ def test_warning(self): warnings.simplefilter('error', SyntaxWarning) compile_command(r"'\e'", symbol='exec') - def test_incomplete_warning(self): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') - self.assertIncomplete("'\\e' + (") - self.assertEqual(w, []) + # TODO: RUSTPYTHON + #def test_incomplete_warning(self): + # with warnings.catch_warnings(record=True) as w: + # warnings.simplefilter('always') + # self.assertIncomplete("'\\e' + (") + # self.assertEqual(w, []) + # TODO: RUSTPYTHON + @unittest.expectedFailure def test_invalid_warning(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always')