Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#158,986 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

Leggi Lib/profiling/sampling/module_utils.py, in particolare extract_module_name() e le informazioni sui percorsi fornite da get_python_path_info(). Riproduci il caso segnalato usando sysconfig.get_path('purelib') e lo snippet fornito, quindi cerca i test esistenti sul campionamento del profiling. Il lavoro è concluso quando vince la directory corrispondente più specifica, la libreria standard vince in caso di parità e l’esempio classifica requests.api come site-packages senza classificare erroneamente i file della libreria standard.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
77.6k
Fork
37.6k
Merge medio
1g 10h
PR unite (30g)
573

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/cpython

Tutte le issue di python/cpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.