python / python/cpython

Docs: missing mention of bytes-like object in eval/exec() documentation

Offen
#148,942 7 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

docs
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Documentation
Documentation

In Doc/library/functions.rst, the sentences that describe the source parameter for the exec() function read:

This function supports dynamic execution of Python code. source must be either a string or a code object. If it is a string, the string is parsed as a suite of Python statements which is then executed (unless a syntax error occurs). [1]_ If it is a code object, it is simply executed.

This explicitly restricts the source parameter to a string or a code object. However, the actual implementation accepts bytes-like objects (such as bytes, bytearray, and memoryview) as well, parsing them internally via the buffer protocol. Because the sentence omits this, users can easily misunderstand that passing bytes is unsupported.

Suggested change

This function supports dynamic execution of Python code. source must be a string, a bytes-like object, or a code object. If it is a string or a bytes-like object, it is parsed as a suite of Python statements which is then executed (unless a syntax error occurs). [1]_ If it is a code object, it is simply executed.

Adding "a bytes-like object" makes the documentation accurately reflect the underlying implementation. Changing the subsequent sentence ensures logical consistency for how these types are parsed.

Linked PRs
  • gh-148943

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Öffne Doc/library/functions.rst und suche die Dokumentation zu exec(), in der der Parameter source beschrieben wird. Vergleiche die Formulierung mit den im Issue genannten unterstützten Fällen string, bytes-like object und code object. Erledigt ist die Aufgabe, wenn die Dokumentation bytes-like objects korrekt erwähnt und erklärt, dass strings und bytes-like objects geparst werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
documentation
Issue-Typ
Dokumentation
Schwierigkeit
1/5
Geschätzter Aufwand
Unter einer Stunde
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

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