Skip to content

gh-155258: Make the curses.complexstr signature introspectable - #155259

Open
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-complexstr-signature
Open

gh-155258: Make the curses.complexstr signature introspectable#155259
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-complexstr-signature

Conversation

@fedonman

@fedonman fedonman commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

complexstr's two optional parameters were declared object = NULL, and NULL has no
Python repr, so Argument Clinic wrote <unrepresentable> into the text signature and
inspect.signature() raised.

Declaring them object(c_default="NULL") = None makes the default representable and
leaves the C default as NULL, so "omitted" and "given" stay distinguishable:

before:
  complexstr:  ValueError: <class 'curses.complexstr'> builtin has invalid signature
  __text_signature__: (cells, /, attr=<unrepresentable>, pair=<unrepresentable>)
after:
  signature: (cells, /, attr=None, pair=None)

Behaviour does not change. The six constructor forms that pass or omit attr and pair,
with a string and with a sequence, give identical results before and after, including the
three that raise. 37 other stdlib parameters already use this declaration.

test_curses passes under TERM=xterm-256color and vt100. The new assertion fails
without the change, with the ValueError above.

complexstr is new in 3.16, so there is no NEWS entry.

Comment thread Modules/_cursesmodule.c
An iterable of cells, each a complexchar or a str.
/
attr: object = NULL
attr: object(c_default="NULL") = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_weakref.proxy uses the same declaration and folds the explicit value back — if (callback == Py_None) callback = NULL; in Objects/weakrefobject.c — so proxy(x, None) behaves like omitting it.

Here None counts as "given" rather than "omitted".

complexstr(["A"], attr=None)  TypeError: attr and pair can only be given with a string

So the signature would advertise a default that can't be passed. Should explicit None be treated as "not given" here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants