Feature or enhancement
Like mentioned before for datetime classes, inspect.signature() also fails on many classes (and some functions) in builtins. However, this is not universal behaviour, as inspect.signature() works well with some classes (and most functions) in builtins.
The functions and classes in builtins that inspect.signature() supports have a str __text_signature__ pseudo-attribute, e.g.:
>>> divmod.__text_signature__
'($module, x, y, /)'
>>> complex.__text_signature__
'(real=0, imag=0)'
The proposed enhancement is to add the same __text_signature__ to others:
- Functions:
anext, breakpoint, dir, getattr, iter, max, min, next, vars
- Classes:
bool, filter, int, map, range, slice, str, and many more, incl. all Exception classes
Pitch
This addition will help consistency and avoid confusion and the need for special-casing.
Example
I ran into this when coding an arity() function using inspect.signature().parameters. My arity() works e.g. for float and complex, but fails for int, which was unexpected and confusing.
Beneficial side-effect
Likely, this will also improve help() output, e.g.
>>> help(iter)
iter(...) <<< signature missing
Get an iterator from an object.
Already available
This might seem challenging for some of the builtins functions and classes that have multiple signatures (e.g. iter(iterable) next to iter(callable, sentinel)). However, these are already available in the typeshed stub file, builtins.pyi.
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.