python / python/cpython

Move getmethparlist function from turtle to inspect module

Offen
#137,387 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stdlib topic-tkinter type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Feature or enhancement

Proposal:

The getmethpartlist turtle module function does work which seems to be supposed to be done by the inspect module.

In fact, getmethpartlist calls inspect.signature and then iterates over it to produce a call to the callable. Perhaps this second part could also be implemented in the inspect module.

In an issue, @terryjreedy said, “For calls that just want the call signature, I wonder if calling getmethodparlist could be replaced by calling signature.”

So, my suggestion is to add two new methods to Signature class, which:

  1. Returns the call:
class Signature():
    def as_call(self) -> string : ...
  1. Returns a new Signature without the first parameter if ob is a method:
class Signature():
    def as_function(self): ...

Then, getmethpartlist could be:

def getmethpartlist(ob):
    defs = inspect.signature(ob).as_function()
    call = defs.as_call()
   return str(defs), call

Thoughts?

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

https://discuss.python.org/t/move-getmethparlist-function-from-turtle-to-inspect-module/97172

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

Überprüfe zuerst getmethpartlist in Lib/turtle.py und die bestehende inspect.Signature API. Lies die verknüpfte Diskussion und den vorherigen Issue-Kommentar, um zu bestimmen, ob die Generierung von Aufrufen und die Behandlung von Methodenparametern in inspect gehören. Als erledigt gilt die Aufgabe, wenn eine abgestimmte API und ein abgestimmtes Verhalten feststehen, bevor der Implementierungsumfang festgelegt werden kann.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Aktiv
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

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