django icon indicating copy to clipboard operation
django copied to clipboard

Simplified django.utils.functional.lazy().

Open bluetech opened this issue 5 years ago • 7 comments

I have split the changes into small commits with rationale in the commit message, to make it easier to review and drop undesirable changes if needed. Should probably be squashed before merging.

~~The last commit "Fixed wrong caching of class preparation." fixes a performance issue that affected us in production. It can be applied separately.~~ Moved to a separate PR: #11399.

bluetech avatar May 03 '19 11:05 bluetech

The CI failure is unrelated: hudson.plugins.git.GitException: Failed to fetch from git://github.com/django/django.git.

bluetech avatar May 03 '19 14:05 bluetech

I rebased and removed a bad commit; the CI passed now.

bluetech avatar Jul 30 '19 17:07 bluetech

Based on my comments, are we sure that there isn't some untested case that has changed?

In your example lazy(lambda: 1, str)(), the function returns an int but the specified resultclass is str. This I believe is already "illegal" and breaks the contract of lazy and will cause super-confusing issues to anyone who does this by mistake. So I think it's OK.

bluetech avatar Jul 31 '19 21:07 bluetech

In your example lazy(lambda: 1, str)(), the function returns an int but the specified resultclass is str. This I believe is already "illegal" and breaks the contract of lazy and will cause super-confusing issues to anyone who does this by mistake. So I think it's OK.

Yeah, that was a sloppy example, but it "worked" before. I fear that we are now claiming str and bytes to be equivalent which definitely feels like a regression.

It seems ill-defined what makes sense here. The (now-removed) code that asserts that bytes and str are incompatible. The undocumented invalid combinations, e.g. str and int. The apparently valid str, tuple and list for get_format_lazy().

Maybe all the complexity is just a hang over from the old Python 2 days of str vs unicode and not all that has been removed.

ngnpope avatar Jul 31 '19 22:07 ngnpope

Yeah, that was a sloppy example, but it "worked" before.

I don't think bug-compatibility should be kept here, especially since making this mistake is very visible so it's unlikely that some code has this bug and is working correctly.

I fear that we are now claiming str and bytes to be equivalent which definitely feels like a regression.

I don't quite follow, can you clarify what you mean by equivalent?

Maybe all the complexity is just a hang over from the old Python 2 days of str vs unicode and not all that has been removed.

That's my understanding, that the _delegate_bytes and _delegate_str is only Python2 compat legacy. Why should str and bytes be special otherwise?

bluetech avatar Aug 01 '19 10:08 bluetech

I couldn't resist adding another commit, "Changed proxy to prepare eagerly." (the commit message explains).

bluetech avatar Apr 26 '20 21:04 bluetech

Rebased. The two conflicts were with 577f2338f16bea055abc49c5a43fa3ecb05dffc8 and 775b796d8d13841059850d73986d5dcc2e593077 (cc @hramezani) which were not semantic conflicts, except for the test which is now passing because having both str and bytes in resultclasses is now allowed.

bluetech avatar Sep 19 '21 16:09 bluetech

Merged the first two commits in 0a132de7ebe1e2679ff7d7f6b6e1ad920828dd90 and 066aabcb77579cf8d549119c860d11cd15e3eef1.

felixxm avatar Mar 30 '23 10:03 felixxm

@bluetech Hi! I'm doing some PR cleanup, would you have time to update this PR with the latest main? Thank you!

nessita avatar Apr 19 '23 15:04 nessita

@bluetech Let me know if you don't have time to keep working on this, I'm eager to move it forward.

felixxm avatar Apr 19 '23 15:04 felixxm

I might be able to pick this up. Have a few ideas for further improvements.

ngnpope avatar Apr 19 '23 18:04 ngnpope

@felixxm @ngnpope Would be happy if you pick this up. It will take me some effort to page these changes in. But I can do the rebase if that would help - let me know.

bluetech avatar Apr 19 '23 20:04 bluetech

Rebased.

felixxm avatar Apr 20 '23 07:04 felixxm

Superseded by #16954.

ngnpope avatar Jun 07 '23 12:06 ngnpope