Opened 12 years ago

Closed 12 years ago

# [with patch, positive review] Fix cached_function to handle defaults better

Reported by: Owned by: boothby boothby minor sage-4.1.2 misc craigcitro Sage 4.1.2.alpha4 Tom Boothby Robert Miller

### Description

We expect the following example to take about 10 seconds:

```sage: @cached_function
sage: def foo(x = 5):
...       print "computing foo(%s)"%x
...       sleep(10)
...       return 0
sage: w = walltime()
sage: foo()
computing foo(5)
sage: foo(5)
computing foo(5)
sage: foo(x=5)
computing foo(5)
sage: print "that took %s seconds!"%walltime(w)
that took 29.9967029095 seconds!
```

... but that obviously isn't the case. fix it!

### comment:1 Changed 12 years ago by boothby

• Summary changed from Fixed cached_function to handle defaults better. to Fix cached_function to handle defaults better. [with patch, not ready]

### comment:2 Changed 12 years ago by boothby

• Summary changed from Fix cached_function to handle defaults better. [with patch, not ready] to Fix cached_function to handle defaults better. [with patch, needs review]

### comment:3 Changed 12 years ago by rlm

• Summary changed from Fix cached_function to handle defaults better. [with patch, needs review] to Fix cached_function to handle defaults better. [with patch, needs work]

Here's a problem:

```sage: class Foo:
def bar(self, a, b, c=0, d=None):
return a
sage: A = Foo()
sage: A.bar(1,2,3,4)
1
sage: from sage.misc.function_mangling import ArgumentFixer
sage: AA = ArgumentFixer(A.bar)
sage: AA.fix_to_named(1,2,3,4)
((), (('self', 1), ('a', 2), ('b', 3), ('c', 4), ('d', None)))

```

Here, self isn't 1. a should be 1.

### comment:4 Changed 12 years ago by rlm

Sorry, my gripe should be that "classmethod" is undocumented.

### comment:5 Changed 12 years ago by boothby

• Summary changed from Fix cached_function to handle defaults better. [with patch, needs work] to Fix cached_function to handle defaults better. [with patch, needs review]

### comment:6 Changed 12 years ago by rlm

• Summary changed from Fix cached_function to handle defaults better. [with patch, needs review] to Fix cached_function to handle defaults better. [with patch, positive review]

Bing!

### comment:7 Changed 12 years ago by mvngu

• Authors changed from boothby to Tom Boothby
• Merged in set to Sage 4.1.2.alpha3
• Milestone set to sage-4.1.2
• Resolution set to fixed
• Reviewers set to Robert Miller
• Status changed from new to closed
• Summary changed from Fix cached_function to handle defaults better. [with patch, positive review] to [with patch, positive review] Fix cached_function to handle defaults better

### comment:8 Changed 12 years ago by mvngu

• Merged in changed from Sage 4.1.2.alpha3 to Sage 4.1.2.alpha4

There is no 4.1.2.alpha3. Sage 4.1.2.alpha3 was William Stein's release for working on the making the notebook a standalone package.

Note: See TracTickets for help on using tickets.