gh-127949: fix `DeprecationWarning` in test_inspect.py (#128215)

This commit is contained in:
Thomas Grainger 2024-12-24 09:43:31 +00:00 committed by GitHub
parent 30efede33c
commit 3f6a618e49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 15 deletions

View File

@ -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,
@ -205,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))
@ -1166,16 +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.addCleanup(asyncio.set_event_loop_policy, None)
self.assertSourceEqual(asyncio.run(mod2.func225()), 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()), 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)