python / python/cpython

Lib/pydoc.py's _is_stdlib_module() fails when source path contains symlinks

Đang mở
#148,314 7 bình luận 0 reaction 1 người được giao Xem trên GitHub

@FFY00 đang làm issue này rồi.

Từ ngày 22/6/2026.

stdlib type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Bug report

Bug description:

In my particular setup, both my cpython source and build dirs are normally referred to via symlinks.

With this setup, test.test_pydoc.test_pydoc fails. This seems to have happed since 78a50ee10ef73296eba98899d496bff3915ddc41

The output is below, but I think it boils down to _is_stdlib_module() - the file.startswith(basedir) call failing. In my setup, basedir is set by the call basedir = os.path.join(srcdir, 'Lib') just above.

basedir then effectively has had its symlinks resolved (or moreover, srcdir has). file has not. So the .startswith() call returns False.

This fixes it, but I have no idea what the broader implications are. For example, what if sysconfig.is_python_build() is false? Then builddir will probably remain with unresolved symlinks.

@@ -536,6 +537,7 @@ def _is_stdlib_module(self, object, basedir=None):
         try:
             file = inspect.getabsfile(object)
+            file = str(pathlib.Path(file).resolve())
         except TypeError:
             file = '(built-in)'

Here's the failing test cases.

======================================================================
ERROR: test_mixed_case_module_names_are_lower_cased (test.test_pydoc.test_pydoc.PydocDocTest.test_mixed_case_module_names_are_lower_cased)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/nick/src/cpython-trunk/Lib/test/test_pydoc/test_pydoc.py", line 469, in test_mixed_case_module_names_are_lower_cased
    self.assertIn('xml.etree.elementtree', doc_link)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nick/src/cpython-trunk/Lib/unittest/case.py", line 1189, in assertIn
    if member not in container:
       ^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not a container or iterable

======================================================================
FAIL: test_online_docs_link (test.test_pydoc.test_pydoc.PydocDocTest.test_online_docs_link)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/nick/src/cpython-trunk/Lib/test/test_pydoc/test_pydoc.py", line 490, in test_online_docs_link
    self.assertIsNotNone(doc_link)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
AssertionError: unexpectedly None

======================================================================
FAIL: test__get_version (test.test_pydoc.test_pydoc.TestInternalUtilities.test__get_version)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/nick/src/cpython-trunk/Lib/test/test_pydoc/test_pydoc.py", line 2391, in test__get_version
    self.assertEqual(len(w), 0)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^
AssertionError: 1 != 0

----------------------------------------------------------------------
Ran 118 tests in 2.274s

FAILED (failures=2, errors=1)
test test.test_pydoc.test_pydoc failed
0:00:02 load avg: 2.42 [1/1/1] test.test_pydoc.test_pydoc failed (1 error, 2 failures)

== Tests result: FAILURE ==

1 test failed:
    test.test_pydoc.test_pydoc

Total duration: 2.4 sec
Total tests: run=118 failures=2
Total test files: run=1/1 failed=1
Result: FAILURE
CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs
  • gh-151897

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.