On 11 October 2016 at 17:21, David Navarro wrote:
> Something like this
>
> In [1]: def a(): pass
> In [2]: def r(): raise RuntimeError('Do not forget to call this')
> In [3]: a.__bool__ = r
> In [4]: if a: pass
>
> I don't have an environment to test if this is possible. This would allow
> markin
On 11 October 2016 at 23:59, Paul Moore wrote:
> Certainly. But the whole point of the warning is to catch people who
> do the wrong thing. All I'm saying is that the new warning would cause
> problems for people who omit a (currently unnecessary) "is None" check
> in the process of protecting peo
One option would be to decorate those functions and provide an
implementation to __bool__ or __nonzero__ which raises an exception.
Something like this
In [1]: def a(): pass
In [2]: def r(): raise RuntimeError('Do not forget to call this')
In [3]: a.__bool__ = r
In [4]: if a: pass
I don't have a
On 10/11/2016 07:00 AM, Steven D'Aprano wrote:
On Tue, Oct 11, 2016 at 02:41:34PM +0200, Sven R. Kunze wrote:
on django-developers, an intriguing idea appeared:
https://groups.google.com/d/msg/django-developers/4bntzg1HwwY/HHHjbDnLBQAJ
"""
It seems to me that the default `method.__bool__` is
On Tue, Oct 11, 2016 at 02:41:34PM +0200, Sven R. Kunze wrote:
> Hey python-ideas,
>
> on django-developers, an intriguing idea appeared:
> https://groups.google.com/d/msg/django-developers/4bntzg1HwwY/HHHjbDnLBQAJ
>
> """
> It seems to me that the default `method.__bool__` is undesirable in
>
On 11 October 2016 at 14:38, Eric Snow wrote:
> On Tue, Oct 11, 2016 at 7:02 AM, Paul Moore wrote:
>> Interesting idea. There may be some issues - consider an object that
>> may optionally have a handler method handle_event, and you want to
>> call that method if it exists:
>>
>> handler = ge
On Tue, Oct 11, 2016 at 7:02 AM, Paul Moore wrote:
> Interesting idea. There may be some issues - consider an object that
> may optionally have a handler method handle_event, and you want to
> call that method if it exists:
>
> handler = getattr(obj, 'handle_event', None)
> if handler:
>
On 11 October 2016 at 13:41, Sven R. Kunze wrote:
> maybe they could benefit
> from a patch where `if`-statements give a warning/error when the expression
> is a callable (with the default `FunctionType.__bool__`?
[...]
> What do you think about that Python emitting an warning/error as described
>
Hey python-ideas,
on django-developers, an intriguing idea appeared:
https://groups.google.com/d/msg/django-developers/4bntzg1HwwY/HHHjbDnLBQAJ
"""
It seems to me that the default `method.__bool__` is undesirable in
Jinja2 templates. I do not know Jinja2 well enough, but maybe they could
ben