Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Offen Anfängerfreundlich
#158,986 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
72/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
tooling

Rechercherichtung

Lies Lib/profiling/sampling/module_utils.py, insbesondere extract_module_name() und die Pfadinformationen von get_python_path_info(). Reproduziere den gemeldeten Fall mit sysconfig.get_path('purelib') und dem bereitgestellten Snippet und suche anschließend nach vorhandenen Tests für Profiling-Sampling. Das Ziel ist erreicht, wenn das spezifischste passende Verzeichnis gewinnt, die Standardbibliothek bei Gleichstand gewinnt und das Beispiel requests.api als site-packages klassifiziert, ohne Dateien der Standardbibliothek falsch zu klassifizieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
Vorherrschende Sprache
Python
Sterne
77.6k
Forks
37.6k
Ø Merge
1 T. 20 Std.
Gemergte PRs (30 T.)
593

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/cpython

Alle Issues in python/cpython

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.