>
> On the other hand, maybe it's a good idea to report a warning in the
> __bool__ method? In most cases, bool(AnonymousUser) is a programming error,
> and not a valid code, so this might be helpful.
>
bool(AnonymousUser) is very pythonic, not a "programming error". The rules
for python's truthy/
{% if request.user %} is a perfectly valid way to check if the user object is
available in the template. I don't think we should change that or give a
warning.
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" gro
In my mental model, the request either was sent by a user (that has a User
object) or not (and in this case it should be None, or at least something
that works like None). However, looks like the majority of you have a
different model, so I'm not going to press for that.
On the other hand, maybe i
I second the objections; my assumption when reading the line 'if
request.user:' is that it's shorthand for 'if request.user is None', which
is not the case.
Grepping a project's code for incorrect usage of 'request.user' is simple
enough, so hopefully that will suffice. I don't recommend this beca
My thoughts from the ticket, "The Django test suite passes with the change
but I feel like that could have some backwards compatibility concerns. Also
"explicit is better than implicit"?
On Wednesday, May 31, 2017 at 12:44:51 PM UTC-4, Linus Lewandowski wrote:
>
> I suggest adding __bool__() met
I'm afraid I'm -1 on this. We already have if request.user.is_authenticated and
request.user.is_anonymous which are both more explicit and pythonic.
Additionally all python classes, and thus instances of User atm, are by
default truthy, so implementing this custom __bool__ introduces space for
more
I suggest adding __bool__() method returning False to the AnonymousUser
class.
This way it'll be possible to check if the user is authenticated by simply
writing "if request.user:"
It's a frequent source of bugs (at least for me, but probably I'm not
alone) that right now this code returns Tru