Opened 6 years ago

Closed 4 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: master
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 6 years ago.
patch that deeply "copy" a class methods
deep_copy.patch (2.3 KB) - added by Amirouche 6 years ago.
added a test
lazy_base_class_aware.diff (2.3 KB) - added by Amirouche 6 years ago.
lastest version of the patch :)
lazy.with_dir.patch (1.5 KB) - added by Amirouche 5 years ago.
git format

Download all attachments as: .zip

Change History (12)

Changed 6 years ago by Amirouche

Attachment: deep_lazy.diff added

patch that deeply "copy" a class methods

comment:1 Changed 6 years ago by Amirouche

Version: 1.2SVN

comment:2 Changed 6 years ago by Amirouche

Has patch: set
Type: UncategorizedBug

Changed 6 years ago by Amirouche

Attachment: deep_copy.patch added

added a test

comment:3 Changed 6 years ago by Luke Plant

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 Changed 6 years ago by Amirouche

Cc: Amirouche added

changed the test & added proper documentation

Changed 6 years ago by Amirouche

Attachment: lazy_base_class_aware.diff added

lastest version of the patch :)

comment:5 Changed 6 years ago by Luke Plant

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 Changed 6 years ago by Luke Plant

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.

Changed 5 years ago by Amirouche

Attachment: lazy.with_dir.patch added

git format

comment:7 Changed 5 years ago by Amirouche

Resolution: fixed
Status: closedreopened
UI/UX: unset

new patch which avoids using double underscores.

comment:8 Changed 4 years ago by Luke Plant

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