gh-148314: Fix pydoc not recognising stdlib modules behind a symlink#151897
gh-148314: Fix pydoc not recognising stdlib modules behind a symlink#151897iamsharduld wants to merge 1 commit into
Conversation
…mlink _is_stdlib_module() compared the module file against the standard library base directory without resolving symlinks. When the source tree was referenced through a symlink, basedir (from sysconfig's srcdir) and the module file path had symlinks resolved inconsistently, so the startswith() prefix check failed and stdlib modules were treated as third-party. Resolve symlinks on both paths before comparing.
|
The only failing check here, This PR only touches pure-Python code in |
|
Closing, I'm sorry but as noted in the issue this has already been assigned to someone (#148314 (comment)). We also need a more general solution for this issue. |
pydoc.Doc._is_stdlib_module()compares the module file against the standardlibrary base directory with
file.startswith(basedir).filecomes frominspect.getabsfile()(which usesos.path.abspath, so symlinks are notresolved), while
basediris derived fromsysconfig.get_config_var('srcdir'),which on a source build can already have symlinks resolved. When the source tree
is referenced through a symlink the two paths have symlinks resolved
inconsistently, the prefix check fails, and standard-library modules are
classified as third-party (for example
pydocthen omits the link to the onlinedocumentation, and
test_pydocfails).Resolve symlinks on both
basedirandfilebefore comparing. In the common,non-symlinked case
realpath()is a no-op.A regression test is added that points a module's
__file__through a symlinkand checks that
_is_stdlib_module()still recognises it.