Skip to content

PEP 749: classmethod and staticmethod do not implement annotation wrapper semantics #8494

Closed

Description

@youknowone

Feature

PEP 749 specifies writable __annotate__ and __annotations__ attributes for classmethod and staticmethod. Reading should retrieve and cache the wrapped callable's value in the wrapper's __dict__; writing should update only the wrapper, not the wrapped callable.

Minimal reproduction:

def f() -> Missing:
    pass

for wrapper in (classmethod(f), staticmethod(f)):
    Missing = int
    print(type(wrapper).__name__, wrapper.__annotations__)
    print("__annotations__" in wrapper.__dict__)

    wrapper.__annotations__ = {"x": str}
    print("wrapper:", wrapper.__annotations__)
    print("wrapped:", f.__annotations__)

CPython 3.14.6 caches __annotations__ in each wrapper and leaves f.__annotations__ unchanged after assignment.

RustPython does not cache the delegated value in the wrapper for the unresolved-name case, and assignment mutates the wrapped function's annotations. This is already represented by the expectedFailure marker on ClassPropertiesAndMethods.test_classmethod_staticmethod_annotations in Lib/test/test_descr.py.

Python Documentation or reference to CPython source code

Activity

  1. hyoinandout commented on Aug 12, 2026

    @hyoinandout
    Contributor

    take

  2. hyoinandout commented on Sep 20, 2026

    @hyoinandout
    Contributor

    fixed by #8701 @youknowone could you have a check?

  3. youknowone commented on Sep 20, 2026

    @youknowone
    MemberAuthor

    @hyoinandout thank you for confirming!

  4. youknowone commented on Oct 6, 2026

    @youknowone
    MemberAuthor

    The originally reported problem no longer reproduces on current main. Closing per the recheck in #8982.

    — commented by Grok 4.6

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

Metadata

Metadata

Assignees

Labels

C-compatA discrepancy between RustPython and CPython

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions