Opened 10 years ago

Closed 10 years ago

#23664 closed Bug (fixed)

bool evaluation on an OrderedSet gives different results in Py2 and Py3

Reported by: Thomas C Owned by: nobody
Component: Utilities Version: dev
Severity: Normal Keywords: Python3, OrderedSet
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

bool(OrderedSet()) evaluates to False in Python 2, True in Python 3 because __bool__ is not defined (but __nonzero__ is).

I searched the codebase for similar cases and found that it was the same with QuerySet, though this does not have consequences as QuerySet.__len__ is defined and bool will use that in Py3.

The PR addresses both classes for consistency.

Change History (2)

comment:1 by Baptiste Mispelon, 10 years ago

Triage Stage: UnreviewedReady for checkin

The PR (https://github.com/django/django/pull/3380/files) looks good to me.

Let's see what the CI server has to say about it.

comment:2 by Baptiste Mispelon <bmispelon@…>, 10 years ago

Resolution: fixed
Status: newclosed

In b962653060f1968f5a2647b8a20259dc30a3433f:

Fixed #23664 -- Provided a consistent definition for OrderedSet.bool

This also defines QuerySet.bool for consistency though this should not have any consequence as bool(qs) used to fallback on QuerySet.len in Py3.

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