Skip to content

Commit fdc59f3

Browse files
zangjiuchengclaude
andcommitted
fix(gh-151626): handle frozen os.path on Windows in test_aliased_target
On Windows, os.path resolves to ntpath which is a frozen module (origin='frozen', cached=None). Calling cache_from_source('frozen') fabricates a nonsensical path that mismatches the subprocess output of None. Guard the cache_from_source call on cached being non-None. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e20d6a2 commit fdc59f3

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

Lib/test/test_inspect/test_inspect.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6660,9 +6660,13 @@ def test_details_option_with_aliased_target(self):
66606660
# assert_python_ok() runs the subprocess in isolated mode (-I), which
66616661
# ignores PYTHONPYCACHEPREFIX, so compute the expected cached path the
66626662
# same way (i.e. without any pycache prefix) to stay independent of the
6663-
# environment the test suite is run in.
6664-
with support.swap_attr(sys, 'pycache_prefix', None):
6665-
cached = importlib.util.cache_from_source(module.__spec__.origin)
6663+
# environment the test suite is run in. For frozen modules (e.g.
6664+
# ntpath on Windows) there is no cached path; keep it None.
6665+
if module.__spec__.cached is not None:
6666+
with support.swap_attr(sys, 'pycache_prefix', None):
6667+
cached = importlib.util.cache_from_source(module.__spec__.origin)
6668+
else:
6669+
cached = None
66666670
# Full rendering check on the expected output
66676671
expected_lines = [
66686672
f'Target: {defining_target} (looked up as "{cli_target}")',

0 commit comments

Comments
 (0)