Title: inspect.Signature: Add Signature.format method to match formatargspec functionality
Type: enhancement Stage:
Components: Versions: Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: yselivanov Nosy List: brett.cannon, larry, ncoghlan, terry.reedy, yselivanov
Priority: normal Keywords:

Created on 2014-01-29 17:30 by yselivanov, last changed 2014-01-29 18:56 by terry.reedy.

Messages (2)
msg209660 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-01-29 17:30
The ability to fine-tune formatting of Signature (currently Signature.__str__) might be useful for pydoc and idle.
msg209668 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-01-29 18:56
For an api, given that we have
formatargvalue(*getargvalues, ...)
formatargspec(*getfullargspec, ...)
we might add
formatsignature(signature, ...)
with the default being the same as str(signature).

I checked the first 80 hits at
(which I found with 'search code' on Google) and 10-15% used one of the extended args. Another at least 5% used [1:=1] to strip of '(' and ')', so any new function might have 'parens=True' option.

Idle uses the default formatargspec, like almost all other uses, and I presume str(sig) is the same except for where formatargspec is arguably wrong (bound methods).  A calltip is a tip, not a doc, so I am most concerned that parameter names not be misleading, as in pattern.match(string) having the parameter misnamed 'pattern' in the C code and I presume, in .signature (absent being fixed). But that is not .signature's fault.
Date User Action Args
2014-01-29 18:56:22terry.reedysetmessages: + msg209668
2014-01-29 17:30:33yselivanovcreate