Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#27309 closed Bug (fixed)

Add CallableBool.__hash__()

Reported by: Reto Aebersold Owned by: nobody
Component: Utilities Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

As CallableBool has no hash method, membership test operations for sets do not work:

from django.utils.deprecation import CallableTrue
assert CallableTrue in {True}

TypeError: unhashable type: 'CallableBool'

Adding a hash method solves this problem:

def __hash__(self):
    return hash(self.value)

Change History (5)

comment:1 Changed 3 years ago by Reto Aebersold

Component: UncategorizedUtilities
Description: modified (diff)
Type: UncategorizedBug

comment:2 Changed 3 years ago by Tim Graham

Description: modified (diff)
Has patch: set
Summary: Missing Hash function in CallableBoolAdd CallableBool.__hash__()
Triage Stage: UnreviewedReady for checkin

It seems a bit odd to have such code, but I suppose it doesn't hurt.

comment:3 Changed 3 years ago by Reto Aebersold

Yes, seems strange. I ran into this issue using Django REST framework. When serializing user.is_authenticated it is runs through this check and fails.

comment:4 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 3ab55c1a:

Fixed #27309 -- Added CallableBool.hash().

comment:5 Changed 3 years ago by Tim Graham <timograham@…>

In c473235b:

[1.10.x] Fixed #27309 -- Added CallableBool.hash().

Backport of 3ab55c1a8a58ae6d6791cafbcefaf224d01ff314 from master

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