Skip to content

Function __annotations__ item order does not match CPython #6068

@jackoconnordev

Description

@jackoconnordev

Summary

RustPython function type annotations order does not match Python when accessed via __annotations__.

This causes problems with e.g. functools singledispatch which assumes the types in annotations are in order of leftmost parameter to return type. dataclasses and pydantic are other libraries which could be affected by this. It this is fixed a lot of importlib tests can be updated to python 3.13 as they have started using singledispatch in Lib/importlib/resources/_common.py.

Sample code

str parameter and int return type.

def func(s: str) -> int:
    return int(s)

print(func.__annotations__)

Expected

{'s': <class 'str'>, 'return': <class 'int'>}

Actual

{'return': <class 'int'>, 's': <class 'str'>}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions