python / python/cpython

Semantic and documentation of Interpreter.prepare_main()

Aperta
#137,639 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

docs
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia dalla documentazione di Interpreter.prepare_main() e dalla sua implementazione, in particolare da come vengono combinati ns e kwargs. Determina quali sono i tipi di input accettati previsti e se debbano cambiare i nomi dei parametri o il comportamento, quindi aggiorna la documentazione o il codice correlato e aggiungi o modifica i test pertinenti affinché la semantica dell’API sia esplicita.

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

Valutazione

Stack tecnologico
python
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.