Opened 4 years ago

Closed 4 years ago

#19642 closed Bug (wontfix)

django.utils.functional.lazy issues

Reported by: void Owned by: aaugustin
Component: Core (Other) Version: master
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


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:

Change History (5)

comment:1 Changed 4 years ago by akaariai

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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 Changed 4 years ago by aaugustin

  • Resolution wontfix deleted
  • Status changed from closed to new

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

comment:3 Changed 4 years ago by aaugustin

  • Owner changed from nobody to aaugustin
  • Status changed from new to assigned

comment:4 Changed 4 years ago by void

Patch, which can be used to solve issues in the ticket:

comment:5 Changed 4 years ago by aaugustin

  • Resolution set to wontfix
  • Status changed from assigned to closed

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