python / python/cpython

Semantic and documentation of Interpreter.prepare_main()

Offen
#137,639 1 Kommentar 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

Interpreter.prepare_main() is documented as:

   .. method:: prepare_main(ns=None, **kwargs)
      
      Bind objects in the interpreter's :mod:`!__main__` module.
   
      Some objects are actually shared and some are copied efficiently,
      but most are copied via :mod:`pickle`.  See :ref:`interp-object-sharing`.

But it is not clear what ns is, and how kwargs is related. A module and a class are nemspaces, so can you pass them? Or the SimpleNamespace instance? No. Looking at the code, ns can only be None, a mapping or an iterable of pairs. Is it what was intended? Than it should be documented.

But accepting an iterable of pairs may be not intended. This can hardly be called a namespace. Then the code should be changed from

ns = dict(ns, **kwargs) if ns is not None else kwargs

to

ns = {**ns, **kwargs} if ns is not None else kwargs

And was it necessary to accept None? This is error-prone, as you can accidentally get None instead of a valid value (missing return or missing initialization). {} could be used as a default value, it is fine if it is not mutated. If exclude None, it can be simply written as:

ns = {**ns, **kwargs}

And I suggest to to change the name of the parameter, as it is not a general namespace. "dict" or "mapping" would better reflect its type. "updates" or "changes" could also be used, but then we should also rename "kwargs" to "updates2" or "changes2". Since this is positional-only parameter, changing the name does not break user code.

cc @ericsnowcurrently

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

Beginne mit der Dokumentation zu Interpreter.prepare_main() und dessen Implementierung, insbesondere damit, wie ns und kwargs kombiniert werden. Ermittle die vorgesehenen akzeptierten Eingabetypen und ob sich die Parameternamen oder das Verhalten ändern sollten, und aktualisiere anschließend die Dokumentation oder den zugehörigen Code und füge die relevanten Tests hinzu oder passe sie an, damit die API-Semantik eindeutig ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
documentation
Issue-Typ
Dokumentation
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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