Skip to content

On Python 3.13.0a6+, use the %T format in exception messages - #17

Merged
hroncok merged 2 commits into
fedora-python:mainfrom
hroncok:Tformat
Nov 9, 2026
Merged

hroncok merged 2 commits into
fedora-python:mainfrom
hroncok:Tformat

Conversation

@hroncok

@hroncok hroncok commented Nov 24, 2025

Copy link
Copy Markdown
Member

That avoids the responsibility for a possible raise in Py_TYPE(args[...])->tp_name when the GIL is disabled.

Related to #16

That avoids the responsibility for a possible raise in
Py_TYPE(args[...])->tp_name when the GIL is disabled.

Related to fedora-python#16
@hroncok hroncok mentioned this pull request Nov 24, 2025
3 of 6 tasks

@frenzymadness frenzymadness left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is good as is and it works as expected.

One idea for improvement: What about having a helper like:

/* Set a TypeError complaining that argument `argno` (named `argname`) must be
 * a string rather than the type of `obj`. Uses the %T format on Python
 * 3.13.0a6+, falling back to tp_name on older versions. */
static void
set_crypt_type_error(int argno, const char *argname, PyObject *obj)
{
#if PY_VERSION_HEX >= 0x030d00a6
    PyErr_Format(
        PyExc_TypeError, "crypt argument %d (%s) must be string, not %T",
        argno, argname, obj
    );
#else
    PyErr_Format(
        PyExc_TypeError, "crypt argument %d (%s) must be string, not %s",
        argno, argname, Py_TYPE(obj)->tp_name
    );
#endif
}

and then just calling it twice like:

set_crypt_type_error(1, "word", args[0]);

and

set_crypt_type_error(2, "salt", args[1]);

I have it implemented. Say yes and I'll push it here.

@hroncok

hroncok commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

yes

@hroncok
hroncok merged commit 7d1cb03 into fedora-python:main Nov 9, 2026
5 checks passed
@hroncok
hroncok deleted the Tformat branch November 9, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants