#21351: memoize function needs tests and improvements
-------------------------------------+-------------------------------------
Reporter: EvilDMP | Owner: bouke
Type: | Status: assigned
Cleanup/optimization | Version: master
Component: Utilities | Resolution:
Severity: Normal | Triage Stage: Ready for
Keywords: | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bouke):
* has_patch: 0 => 1
* stage: Accepted => Ready for checkin
Comment:
For ticket completeness bmispelon also left a comment about `memoize(...,
num_args=1)` whilst `get_callable` takes 2 arguments:
> bmispelon 16 hours ago:
> The num_args argument was introduced in
b6812f2d9d1bea3bdc9c5f9a747c5c71c764fa0f specifically for get_callable
(note how it can take two arguments but the num_args is 1).
> I suspect there might be something weird going on but I haven't had time
to look into it and unfortunately, we cannot ask the original committer of
that change anymore :(
Say a function has two parameters and one result, then `A,B -> X` and `A,C
-> Y`. However as the function's cache strategy only accounts for the
first argument, it will always do the same, namely `A,? -> X` UNLESS in
the case of an exception. Now when the exception happened for `A,D -> ?`,
then no cache is written and `A,C -> Y`. However if `A,C -> Y` is executed
FIRST and cached, then `A,? -> Y` and thus `A,D -> Y` -- no exception
being raised.
I have added a test to the PR demonstrate this problem.
--
Ticket URL: <https://code.djangoproject.com/ticket/21351#comment:12>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.620054bc150f1107289172227fc0f3e5%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.