Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

profiling.sampling reports third-party modules as stdlib when site-packages is inside the stdlib directory

未关闭 适合新手
#158,986 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
tooling

调研方向

阅读 Lib/profiling/sampling/module_utils.py,尤其是 extract_module_name() 和 get_python_path_info() 提供的路径信息。使用 sysconfig.get_path('purelib') 和给定的代码片段重现报告中的情况,然后检查现有的 profiling sampling 测试。完成标准是:最具体的匹配目录优先;出现平局时标准库优先;示例将 requests.api 分类为 site-packages,且不会误分类标准库文件。

由索引模型根据 Issue 内容生成。

描述

stdlib topic-profiling type-bug

Bug report

Bug description:

profiling.sampling.module_utils.extract_module_name() checks the stdlib directory before the site-packages directories. In a regular (non-venv) installation site-packages is a subdirectory of the stdlib directory (Lib\site-packages on Windows, lib/pythonX.Y/site-packages for python.org, pyenv, conda or Docker builds, and Lib/site-packages in a source build), so every file installed there matches the stdlib check first.

import os
import sysconfig
from profiling.sampling.module_utils import extract_module_name, get_python_path_info

path_info = get_python_path_info()
filename = os.path.join(sysconfig.get_path('purelib'), 'requests', 'api.py')
print(extract_module_name(filename, path_info))

Output (Windows, <prefix>\Lib is the stdlib directory and <prefix>\Lib\site-packages is the site-packages directory):

('site-packages.requests.api', 'stdlib')

Expected:

('requests.api', 'site-packages')

As a result, the heatmap index lists third-party code under "Standard Library", inside a folder named site-packages, instead of under "Site Packages", and the flamegraph labels of such frames look like get (site-packages.requests.api:10). Doc/library/profiling.sampling.rst describes the heatmap index as organized by type (stdlib, site-packages, project). Only virtual environments (and the user site directory), where site-packages is not inside the stdlib directory, are classified correctly.

Simply checking site-packages first is not enough: on Windows site.getsitepackages() also returns sys.prefix, which is a parent of the stdlib directory and would then capture the stdlib files. The most specific (longest) matching directory should win, with stdlib winning a tie.

CPython versions tested on:

CPython main branch

(Lib/profiling/sampling/module_utils.py is identical on the 3.15 branch.)

Operating systems tested on:

Windows

Linked PRs
  • gh-158993
主要语言
Python
星标
77.6k
派生
37.6k
平均合并
1 天 10 小时
30 天内合并 PR
573

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python/cpython 的其他 Issue

查看 python/cpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。