Ticket #568 (reopened defect)
cache utility does not handle default argument values
| Reported by: | Wichert | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Other | Version: | 0.9.7 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
I got an IndexError? on the args_keys[arg] = args[i] line in _make_dict_from_args() method if I did not pass arguments which had a default value in to a function.
I modified the code to build a list of default arguments and use that instead. This is safer than skipping those arguments in case you change the defaults but your have persisting cache entries in a dbm or memcache.
def _make_dict_from_args(func, args): """Inspects function for name of args""" args_keys = {} argspec = inspect.getargspec(func) if argspec[3] is not None: defaults = (None,)*(len(argspec[0])-len(argspec[3])) + argspec[3] for i, arg in enumerate(argspec[0]): if arg != "self": try: args_keys[arg] = args[i] except IndexError: args_keys[arg] = defaults[i] return args_keys
Change History
Note: See
TracTickets for help on using
tickets.