[Django] #27154: Minor difference in behavior between CallableFalse/CallableTrue and False/True.

24 views
Skip to first unread message

Django

unread,
Aug 30, 2016, 8:55:33 AM8/30/16
to django-...@googlegroups.com
#27154: Minor difference in behavior between CallableFalse/CallableTrue and
False/True.
--------------------------------------+--------------------
Reporter: tomchristie | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.auth | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+--------------------
Original raised as a ticket in REST framework:
https://github.com/tomchristie/django-rest-framework/issues/4439

Something that may confuse users calling `.is_authenticated`...

There's a slight difference in behavior between how the
CallableFalse/CallableTrue instances behave compare to how False/True
behave.

The Python boolean type happens to support the bitwise OR operator, and
its behavior in this case is exactly equivalent to the `or` operator. Eg.
`False | True` returns `True`

The backwards compat CallableFalse/CallableTrue instances do not support
this usage, and will fail with eg. `TypeError: unsupported operand type(s)
for |: 'instance' and 'bool'`

Their behavior is reasonable enough, and the user should really be using
the boolean `or` operator, but we might introduce slightly less friction
(ie don't raise a slightly opaque error message to the user) if we simply
support and allow the bitwise operator in the same way as the boolean
equivalents.

I'm probably a +0 on resolving this, as think it'd save a few folks a bit
of head banging. Certainly wouldn't dispute a `wontfix` categorization.

Tip for easy pickings folks: Should be resolvable by including an `__or__`
method on the CallableFalse/CallableTrue classes.

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

Django

unread,
Aug 30, 2016, 9:10:30 AM8/30/16
to django-...@googlegroups.com
#27154: Minor difference in behavior between CallableFalse/CallableTrue and
False/True.
--------------------------------------+------------------------------------

Reporter: tomchristie | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.auth | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by bmispelon):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

The change seems simple enough and I don't see any drawbacks to adding it.

If we can make our users' lives easier, I'm +1 on it.

If anyone is interested in tackling this, the
`CallableFalse`/`CallableTrue` classes are defined in
`django/utils/deprecation.py`.


Once the change is made, I think we should also discuss backporting it.


Thanks.

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

Django

unread,
Aug 30, 2016, 9:44:40 AM8/30/16
to django-...@googlegroups.com
#27154: Minor difference in behavior between CallableFalse/CallableTrue and
False/True.
--------------------------------------+------------------------------------

Reporter: tomchristie | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.auth | Version: 1.10
Severity: Release blocker | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* severity: Normal => Release blocker


Comment:

The implementation can follow commit
54afa960d1ee8c63635225a0f0a2489971b5aab5.

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

Django

unread,
Aug 31, 2016, 3:49:07 AM8/31/16
to django-...@googlegroups.com
#27154: Minor difference in behavior between CallableFalse/CallableTrue and
False/True.
--------------------------------------+------------------------------------
Reporter: tomchristie | Owner: alexyer
Type: Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 1.10

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by alexyer):

* status: new => assigned
* owner: nobody => alexyer


--
Ticket URL: <https://code.djangoproject.com/ticket/27154#comment:3>

Django

unread,
Aug 31, 2016, 4:14:16 AM8/31/16
to django-...@googlegroups.com
#27154: Minor difference in behavior between CallableFalse/CallableTrue and
False/True.
--------------------------------------+------------------------------------
Reporter: tomchristie | Owner: alexyer
Type: Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 1.10

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by alexyer):

Here is the [https://github.com/django/django/pull/7190 PR]. Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/27154#comment:4>

Django

unread,
Aug 31, 2016, 8:25:50 AM8/31/16
to django-...@googlegroups.com
#27154: Allow comparing CallableFalse/CallableTrue with bitwise or
-------------------------------------+-------------------------------------
Reporter: tomchristie | Owner: alexyer
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.auth | Version: 1.10
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/27154#comment:5>

Django

unread,
Aug 31, 2016, 8:28:24 AM8/31/16
to django-...@googlegroups.com
#27154: Allow comparing CallableFalse/CallableTrue with bitwise or
-------------------------------------+-------------------------------------
Reporter: tomchristie | Owner: alexyer
Type: | Status: closed
Cleanup/optimization |
Component: contrib.auth | Version: 1.10
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"b7fb608142a0be568bc5dce952de5e6aefc2488c" b7fb6081]:
{{{
#!CommitTicketReference repository=""
revision="b7fb608142a0be568bc5dce952de5e6aefc2488c"
Fixed #27154 -- Allowed comparing CallableBool with bitwise or.

Thanks Tim for the review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27154#comment:6>

Django

unread,
Aug 31, 2016, 12:19:02 PM8/31/16
to django-...@googlegroups.com
#27154: Allow comparing CallableFalse/CallableTrue with bitwise or
-------------------------------------+-------------------------------------
Reporter: tomchristie | Owner: alexyer
Type: | Status: closed
Cleanup/optimization |
Component: contrib.auth | Version: 1.10

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"7c57f5cf8cd10b69d0c76ba97ab048ccc2917c55" 7c57f5c]:
{{{
#!CommitTicketReference repository=""
revision="7c57f5cf8cd10b69d0c76ba97ab048ccc2917c55"
[1.10.x] Fixed #27154 -- Allowed comparing CallableBool with bitwise or.

Thanks Tim for the review.

Backport of b7fb608142a0be568bc5dce952de5e6aefc2488c from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27154#comment:7>

Reply all
Reply to author
Forward
0 new messages