Format argument signatures using inspect.Signature on Python 3.x.
Review Request #10632 — Created July 19, 2019 and submitted — Latest diff uploaded
Historically,
inspect.formatargspec()
was used to generate Python code
representing function signatures, but modern versions of Python 3.x
provide better support for this through aninspect.Signature
object.
This can be populated with information about the function (parameters,
annotations, etc.), and a string can be computed from that.Internally,
inspect.formatargspec()
now uses this, but emits a
deprecation warning.We now use
inspect.Signature
when available, and feed in parameters
the same way thatinspect.formatargspec()
does, while avoiding its
deprecation warning. Down the road, we'd be able to use this to support
type annotations as well.
Unit tests pass on Python 2.7, 3.5, 3.6, and 3.7.