Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from annotationlib import Format, ForwardRef
import asyncio
import builtins
import collections
import copy
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
Loading