From e55fc842a2dce073cdd6ca0a8c46c0d6f4abf817 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 24 Dec 2024 08:34:03 +0000 Subject: [PATCH 1/3] fix DeprecationWarning in test_inspect.py --- Lib/test/test_inspect/test_inspect.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index 2c950e46b3ed8a..b01f2e95d5202f 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -1,5 +1,4 @@ from annotationlib import Format, ForwardRef -import asyncio import builtins import collections import copy @@ -73,11 +72,6 @@ def revise(filename, *args): git = mod.StupidGit() -def tearDownModule(): - if support.has_socket_support: - asyncio._set_event_loop_policy(None) - - def signatures_with_lexicographic_keyword_only_parameters(): """ Yields a whole bunch of functions with only keyword-only parameters, @@ -1172,10 +1166,9 @@ def f(self): ) def test_nested_class_definition_inside_async_function(self): import asyncio - self.addCleanup(asyncio.set_event_loop_policy, None) - self.assertSourceEqual(asyncio.run(mod2.func225()), 226, 227) + self.assertSourceEqual(asyncio.run(mod2.func225(), loop_factory=asyncio.EventLoop), 226, 227) self.assertSourceEqual(mod2.cls226, 231, 235) - self.assertSourceEqual(asyncio.run(mod2.cls226().func232()), 233, 234) + self.assertSourceEqual(asyncio.run(mod2.cls226().func232(), loop_factory=asyncio.EventLoop), 233, 234) def test_class_definition_same_name_diff_methods(self): self.assertSourceEqual(mod2.cls296, 296, 298) From a3ec28c2a8b484218e42f1d2df5dc7c4334c4fc0 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 24 Dec 2024 08:39:35 +0000 Subject: [PATCH 2/3] get test_nested_class_definition_inside_async_function working on emscripten and wasi --- Lib/test/test_inspect/test_inspect.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index b01f2e95d5202f..29274107b4a5d1 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -1160,15 +1160,20 @@ def f(self): # This is necessary when the test is run multiple times. sys.modules.pop("inspect_actual") - @unittest.skipIf( - support.is_emscripten or support.is_wasi, - "socket.accept is broken" - ) def test_nested_class_definition_inside_async_function(self): - import asyncio - self.assertSourceEqual(asyncio.run(mod2.func225(), loop_factory=asyncio.EventLoop), 226, 227) + def run(coro): + try: + coro.send(None) + except StopIteration as e: + return e.value + else: + raise RuntimeError("coroutine did not complete synchronously!") + finally: + coro.close() + + self.assertSourceEqual(run(mod2.func225()), 226, 227) self.assertSourceEqual(mod2.cls226, 231, 235) - self.assertSourceEqual(asyncio.run(mod2.cls226().func232(), loop_factory=asyncio.EventLoop), 233, 234) + self.assertSourceEqual(run(mod2.cls226().func232()), 233, 234) def test_class_definition_same_name_diff_methods(self): self.assertSourceEqual(mod2.cls296, 296, 298) From 1b1370633e81988d3001e84770a7a96bbef3507e Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 24 Dec 2024 08:49:28 +0000 Subject: [PATCH 3/3] avoid side dep on asyncio in inspect --- Lib/test/test_inspect/test_inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index 29274107b4a5d1..d536d04d2e7d88 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -199,7 +199,7 @@ def test_excluding_predicates(self): self.assertFalse(inspect.ismethodwrapper(type("AnyClass", (), {}))) def test_ispackage(self): - self.istest(inspect.ispackage, 'asyncio') + self.istest(inspect.ispackage, 'unittest') self.istest(inspect.ispackage, 'importlib') self.assertFalse(inspect.ispackage(inspect)) self.assertFalse(inspect.ispackage(mod))