[Freeipa-devel] DN patch and documentation

Petr Viktorin pviktori at redhat.com
Fri Jul 27 13:14:43 UTC 2012


On 07/26/2012 11:30 PM, John Dennis wrote:
> The DN patch has been reworked. The single largest change was to the DN
> implementation and it's unit test to refactor the AVA, RDN and DN
> classes into a base class that is immutable and a subclass that supports
> editing. This makes these classes fully consistent with the Python
> language definition [...].

Unfortunately, that's not quite true yet.

If an object implements both __hash__ and __cmp__/__eq__, it must ensure 
that two equal objects will have the same hash value -- see 
http://docs.python.org/reference/datamodel.html#object.__hash__

This is not the case: DN(dn) == EditableDN(dn), but hash(DN(dn)) != 
hash(EditableDN(dn)).

Please flag the mutable classes as unhashable by setting __hash__ = None.


> Bottom line for developers. In 99.99% of the cases just continue to use
> DN's as you always have. If you need to modify a DN cast it into a
> EditableDN (e.g. dn = EditableDN(dn)), perform your edit, and if you end
> up passing the dn outside your scope
or using it as a dict key
> you should cast it back to an immutable DN (e.g. dn = DN(dn)

-- 
Petr³




More information about the Freeipa-devel mailing list