Skip to content

inspect.signature() fails on the new curses.complexstr type #155258

Description

@fedonman

Bug description:

curses.complexstr is new in 3.16 and its signature cannot be introspected:

import curses, inspect

print(inspect.signature(curses.complexchar))      # the sibling type
print(curses.complexstr.__text_signature__)
inspect.signature(curses.complexstr)
(text, /, attr=0, pair=0)
(cells, /, attr=<unrepresentable>, pair=<unrepresentable>)
ValueError: <class 'curses.complexstr'> builtin has invalid signature

help(curses.complexstr) still works, but shows the placeholder to the reader:

|  complexstr(cells, /, attr=<unrepresentable>, pair=<unrepresentable>)

Both optional parameters are declared object = NULL
(Modules/_cursesmodule.c:1415 and :1417), and NULL has no Python repr, so Argument
Clinic writes <unrepresentable> into the text signature at
Modules/clinic/_cursesmodule.c.h:105. It is the only one in that file.
curses.complexchar, whose attr and pair have real defaults, introspects fine.

A representable default fixes it without changing behaviour, for example
object(c_default="NULL") = None, which 37 other stdlib parameters already use. _md5.md5
shows the effect: its signature reads string=None while the C default stays NULL, so
"omitted" and "given" remain distinguishable.

The same clinic pattern leaves an <unrepresentable> in 24 other generated files, so this
is not a new kind of problem. complexstr is worth fixing now because it has not shipped
yet.

GH-152262 (gh-152233) added the type. It is the origin of this, not a report of it.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.16new features, bugs and security fixesextension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status
    Done
    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions