GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add inspect.signature support for more builtins · Issue #107161 · python/cpython

Add inspect.signature support for more builtins #107161

New issue
Copy link
New issue
Copy link
Open
Open
Add inspect.signature support for more builtins#107161
Copy link
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

Description

@Dutcho
Dutcho
opened on Jul 23, 2023
Issue body actions

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.

Reacted by Tomas R. and Kale Kundert

Activity

  1. Dutcho
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Jul 23, 2023
  2. Dutcho
    changed the title [-]Add inspect.signature support for builtins[/-] [+]Add inspect.signature support for more builtins[/+] on Jul 23, 2023
  3. iritkatriel
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Nov 27, 2023
  4. serhiy-storchaka
    added this to Inspect issues 🔍on Mar 5, 2024
  5. za3k commented on Mar 1, 2025

    @za3k
    za3k
    on Mar 1, 2025
    More actions

    A small update for python 3.13.1 and a more exhaustive list:

    inspect.signature fails on the following builtins: anext, bytearray, bytes, dict, dir, getattr, int, iter, max, min, next, range, slice, str, super, type, vars

    As well as all error types, which are callable.

    import inspect
    
    failing = []
    for k in dir(__builtins__):
        v = eval(k)
        if not hasattr(v, "__call__"):
            continue
        try:
            sig = inspect.signature(v)
        except:
            failing.append(k)
    
    print(failing)
    
  6. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Mar 1, 2025
  7. skirpichev commented on Mar 1, 2025

    @skirpichev
    skirpichev
    on Mar 1, 2025
    Member
    More actions

    For exception types: #111405

    For mentioned above builtins we can't do anything, until #73536 will be solved.

  8. Dutcho commented on Mar 12, 2025

    @Dutcho
    Dutcho
    on Mar 12, 2025
    Author
    More actions

    It looks #73536 can be solved by multi-signatures. What's required for it to be resolved?

    And for #111405, brian030128 wanted to work on that. Don't know if it ever matured?

  9. skirpichev
    self-assigned this
    on Mar 13, 2025
  10. skirpichev
    removed their assignment
    on Apr 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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

    • Inspect issues 🔍
      Status
      No status
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.