[Django] #23664: bool evaluation on an OrderedSet gives different results in Py2 and Py3

3 views
Skip to first unread message

Django

unread,
Oct 16, 2014, 7:08:07 AM10/16/14
to django-...@googlegroups.com
#23664: bool evaluation on an OrderedSet gives different results in Py2 and Py3
----------------------------+---------------------------------
Reporter: tchaumeny | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: master
Severity: Normal | Keywords: Python3, OrderedSet
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------------------
`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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23664>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 16, 2014, 7:44:22 AM10/16/14
to django-...@googlegroups.com
#23664: bool evaluation on an OrderedSet gives different results in Py2 and Py3
-------------------------------------+-------------------------------------

Reporter: tchaumeny | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: Python3, OrderedSet | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bmispelon):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Ready for checkin


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23664#comment:1>

Django

unread,
Oct 16, 2014, 8:17:35 AM10/16/14
to django-...@googlegroups.com
#23664: bool evaluation on an OrderedSet gives different results in Py2 and Py3
-------------------------------------+-------------------------------------
Reporter: tchaumeny | Owner: nobody
Type: Bug | Status: closed
Component: Utilities | Version: master
Severity: Normal | Resolution: fixed

Keywords: Python3, OrderedSet | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Baptiste Mispelon <bmispelon@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"b962653060f1968f5a2647b8a20259dc30a3433f"]:
{{{
#!CommitTicketReference repository=""
revision="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.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23664#comment:2>

Reply all
Reply to author
Forward
0 new messages