python / python/cpython

Move getmethparlist function from turtle to inspect module

Open
#137,387 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-tkinter type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review getmethpartlist in Lib/turtle.py and the existing inspect.Signature API first. Read the linked discussion and prior issue comment to determine whether call-generation and method-parameter handling belong in inspect. Done requires an agreed API and behavior before implementation scope can be identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.