﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
4506	regroup should rely on __eq__ instead of repr	(removed)	Adrian Holovaty	"Tucked away in django.template.defaulttags.RegroupNode.render is this lil gem-

{{{
for obj in obj_list:
    grouper = self.expression.resolve(obj, True)
    # TODO: Is this a sensible way to determine equality?
    if output and repr(output[-1]['grouper']) == repr(grouper):
        output[-1]['list'].append(obj)
    else:
        output.append({'grouper': grouper, 'list': [obj]})
}}}

re: the TODO... the answer is 'no'.

Aside from the fact it's forcing 2(n-1) repr when n repr would suffice, equality protocol exists exactly for usage in cases like this.  The repr abusage there covers up a few things-
1) bad object implementations that have taken the time to flesh out repr, but not __eq__ which isn't really covering up.  Tough cookies frankly (__eq__/__ne__ are simple methods to implement, and are needed elsewhere- hashing for example).
2) Objects that repr to the same, but have an __eq__ that says they differ.  If __eq__ says it differs, it differs- using an alt equality method is dodging whatever reason the original author had for having __eq__ compare differently (exempting if they just didn't implement __eq__, which is scenario #1).

Either way, the extra repr calls aren't needed- more importantly, repr should *not* be used there.

So... counter args?"		closed	Template system	dev		fixed			Accepted	1	0	0	1	0	0
