Add inspect.signature support for more builtins #107161
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
stdlib
Python modules in the Lib dir
type-feature
A feature request or enhancement
Feature or enhancement
Like mentioned before for
datetime
classes,inspect.signature()
also fails on many classes (and some functions) inbuiltins
. However, this is not universal behaviour, asinspect.signature()
works well with some classes (and most functions) inbuiltins
.The functions and classes in
builtins
thatinspect.signature()
supports have astr
__text_signature__
pseudo-attribute, e.g.:The proposed enhancement is to add the same
__text_signature__
to others:anext
,breakpoint
,dir
,getattr
,iter
,max
,min
,next
,vars
bool
,filter
,int
,map
,range
,slice
,str
, and many more, incl. allException
classesPitch
This addition will help consistency and avoid confusion and the need for special-casing.
Example
I ran into this when coding an
arity()
function usinginspect.signature().parameters
. Myarity()
works e.g. forfloat
andcomplex
, but fails forint
, which was unexpected and confusing.Beneficial side-effect
Likely, this will also improve
help()
output, e.g.Already available
This might seem challenging for some of the
builtins
functions and classes that have multiple signatures (e.g.iter(iterable)
next toiter(callable, sentinel)
). However, these are already available in the typeshed stub file,builtins.pyi
.The text was updated successfully, but these errors were encountered: