Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#15759 closed enhancement (fixed)

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

Reported by: nthiery Owned by:
Priority: major Milestone: sage-6.2
Component: misc Keywords:
Cc: SimonKing Merged in:
Authors: Nicolas M. Thiéry Reviewers: Simon King
Report Upstream: N/A Work issues:
Branch: 6b18661 (Commits) Commit:
Dependencies: Stopgaps:

Description (last modified by robertwb)

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)

Change History (7)

comment:1 Changed 5 years ago by nthiery

  • Branch set to public/ticket/15759
  • Created changed from 01/29/14 09:28:54 to 01/29/14 09:28:54
  • Modified changed from 01/29/14 09:28:54 to 01/29/14 09:28:54

comment:2 Changed 5 years ago by nthiery

  • Authors set to Nicolas M. Thiéry
  • Cc SimonKing added
  • Commit set to 6b18661787e2d518fca76d0a22c4eb5a6ab49a08
  • Reviewers set to Simon King?
  • Status changed from new to needs_review

New commits:

6b18661Implementation of 15759

comment:3 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:4 Changed 5 years ago by SimonKing

  • Reviewers changed from Simon King? to Simon King
  • Status changed from needs_review to positive_review

The code looks good, all tests pass, and in fact in the past I have considered to add the __name__ attribute myself. Positive review.

comment:5 Changed 5 years ago by nthiery

Thanks Simon for the review!

comment:6 Changed 5 years ago by vbraun

  • Branch changed from public/ticket/15759 to 6b18661787e2d518fca76d0a22c4eb5a6ab49a08
  • Resolution set to fixed
  • Status changed from positive_review to closed

comment:7 Changed 5 years ago by robertwb

  • Commit 6b18661787e2d518fca76d0a22c4eb5a6ab49a08 deleted
  • Description modified (diff)

Remove tabs from description.

Note: See TracTickets for help on using tickets.