gh-143886: Ensure function annotations are returned in order of definition (#143888)

Ensure function annotations are returned in order of definition

Previously, when getting type annotations of a function, normal
arguments were returned before positional-only ones in the dictionary.
Since `functools.singledispatch` relies on this ordering being correct
to dispatch based on the type of the first argument, this issue was
causing incorrect registrations for functions with positional-only
arguments.

This commit updates how annotations are generated so that
positional-only arguments are generated and added to the dictionary
before normal arguments.
This commit is contained in:
Carey Metcalfe 2026-04-15 09:24:28 -04:00 committed by GitHub
parent ab45919812
commit cb339d3c9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 2 deletions

View file

@ -1130,10 +1130,10 @@ codegen_annotations_in_scope(compiler *c, location loc,
Py_ssize_t *annotations_len)
{
RETURN_IF_ERROR(
codegen_argannotations(c, args->args, annotations_len, loc));
codegen_argannotations(c, args->posonlyargs, annotations_len, loc));
RETURN_IF_ERROR(
codegen_argannotations(c, args->posonlyargs, annotations_len, loc));
codegen_argannotations(c, args->args, annotations_len, loc));
if (args->vararg && args->vararg->annotation) {
RETURN_IF_ERROR(