Opened 11 years ago

Closed 11 years ago

#19642 closed Bug (wontfix)

django.utils.functional.lazy issues

Reported by: Alexey Boriskin Owned by: Aymeric Augustin
Component: Core (Other) Version: dev
Severity: Normal Keywords: lazy, functional
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've found some issues meditating on the lazy() function. I'm reporting them as one ticket; please tell if I should rather create one per issue.

  • promise, returned by lazy(), has no attributes of original class: lazy() thinks only about methods
  • promise, returned by lazy(), has weird behaviour if resultclass has __mod__ method – it overrides it completely
  • methods of promise, returned by lazy(), lack the __doc__ attribute – docstring is lost
  • if resultclass explicitly define itself as a not hashable with __hash__ = None, promises of that class may still be hashable.

Following diff, when applied, adds four failing tests illustrating that issues: https://gist.github.com/4582334

Change History (5)

comment:1 by Anssi Kääriäinen, 11 years ago

Resolution: wontfix
Status: newclosed

My understanding is that lazy() will just defer the call of the given callable until it is accessed. The idea is to not work as a proxy for an object. So, for that reason marking as wontfix.

If some of the issues are seen as problems in "defer call to method" definition of lazy (the __mod__ issue?), then reopen...

comment:2 by Aymeric Augustin, 11 years ago

Resolution: wontfix
Status: closednew

I'd like to take a look at the __mod__ issue.

comment:3 by Aymeric Augustin, 11 years ago

Owner: changed from nobody to Aymeric Augustin
Status: newassigned

comment:4 by Alexey Boriskin, 11 years ago

Patch, which can be used to solve issues in the ticket: https://gist.github.com/4605065

comment:5 by Aymeric Augustin, 11 years ago

Resolution: wontfix
Status: assignedclosed

The second item was fixed in the patch for #19160. The three others are fairly minor and don't have actual consequences in the current code base.

The patch fixes a few things but it isn't quite production-ready (builtin_method_names = ['__hash__', '__str__'] - ouch)

For these reasons I don't think it's useful to keep this ticket open.


However, as discussed on IRC, it could be a good idea to re-implement lazy() by overriding __getattribute__ rather than by copying methods around, both design-wise and performance-wise (to be benchmarked). Feel free to write a patch for this and open a new ticket!

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