-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Add inspect.signature support for more builtins #107161
Copy link
Copy link
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Projects
Status
No status
Feature or enhancement
Like mentioned before for
datetimeclasses,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
builtinsthatinspect.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,varsbool,filter,int,map,range,slice,str, and many more, incl. allExceptionclassesPitch
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. forfloatandcomplex, 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
builtinsfunctions 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.