Opened 13 years ago

Closed 11 years ago

#15811 closed Bug (fixed)

Lazy doesn't take into account methods defined in parents

Reported by: Amirouche Owned by: nobody
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: Amirouche Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Example:

from django.utils.datastructures import SortedDict
from django.utils.functional import lazy

def a(): return SortedDict([(2,2),(1,1)])

f = lazy(a, SortedDict)()
f[1]

This results in a TypeError

I got a patch ready but not sure if it does what it should do well since I don't grasp all the lazy functionality.

Attachments (4)

deep_lazy.diff (1.5 KB ) - added by Amirouche 13 years ago.
patch that deeply "copy" a class methods
deep_copy.patch (2.3 KB ) - added by Amirouche 13 years ago.
added a test
lazy_base_class_aware.diff (2.3 KB ) - added by Amirouche 13 years ago.
lastest version of the patch :)
lazy.with_dir.patch (1.5 KB ) - added by Amirouche 12 years ago.
git format

Download all attachments as: .zip

Change History (12)

by Amirouche, 13 years ago

Attachment: deep_lazy.diff added

patch that deeply "copy" a class methods

comment:1 by Amirouche, 13 years ago

Version: 1.2SVN

comment:2 by Amirouche, 13 years ago

Has patch: set
Type: UncategorizedBug

by Amirouche, 13 years ago

Attachment: deep_copy.patch added

added a test

comment:3 by Luke Plant, 13 years ago

Component: UncategorizedCore (Other)
Easy pickings: unset
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

'deep copy' is confusing terminology - it normally refers to copy.deepcopy. What you are referring to is checking base class methods. The test name and comments need to be updated accordingly.

In addition, I think that test should not implicitly rely on the fact that SortedDict doesn't have __getitem__ defined - that could easily change. I would define a pair of custom classes that show the problem, probably within the test method itself.

Otherwise, this looks pretty good.

comment:4 by Amirouche, 13 years ago

Cc: Amirouche added

changed the test & added proper documentation

by Amirouche, 13 years ago

Attachment: lazy_base_class_aware.diff added

lastest version of the patch :)

comment:5 by Luke Plant, 13 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

Thanks!

For future reference, when you have updated a patch, you should uncheck the 'Patch needs improvement' flag if you think the patch is up to scratch. A reviewer will set it again if it isn't.

comment:6 by Luke Plant, 13 years ago

Resolution: fixed
Status: newclosed

In [16157]:

Fixed #15811 - lazy() doesn't take into account methods defined in parents

Thanks to abki for the report and patch.

by Amirouche, 12 years ago

Attachment: lazy.with_dir.patch added

git format

comment:7 by Amirouche, 12 years ago

Resolution: fixed
Status: closedreopened
UI/UX: unset

new patch which avoids using double underscores.

comment:8 by Luke Plant, 11 years ago

Resolution: fixed
Status: reopenedclosed

It's not at all obvious to me that this new patch does the same as the existing code, especially given the rather vague definition of 'dir': "return an alphabetized list of names comprising (some of) the attributes of the given object, and of attributes reachable from it."

So I'm closing again. Since the original bug is fixed, please open a new ticket or pull request for any cleanup.

Note: See TracTickets for help on using tickets.
Back to Top