Skip to content

cached_method: __name__ and __module__ attributes; callable as functions / class bound methods #15759

@nthiery

Description

@nthiery

This ticket adds the following features to cached methods to make them
behave more like usual methods:

  • __name__ and __module__ attributes

  • calling them as functions / methods bound on a class:

    class Foo:
        @cached_method
        def f(self):
            ...
    
    sage: instance = Foo()
    sage: Foo.f(instance) is instance.f()
    sage: Foo.__dict__['f'](instance) is instance(f)
    

This makes them compatible with, e.g., deprecated_function_alias:

class Foo:
    @cached_method
    def f(self):
        ...
    bar = deprecated_function_alias(12963, f)

CC: @simon-king-jena

Component: misc

Author: Nicolas M. Thiéry

Branch: 6b18661

Reviewer: Simon King

Issue created by migration from https://trac.sagemath.org/ticket/15759

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions