osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: PEP: add a `no` keyword as an alias for `not`


---------- Forwarded message ---------
From: Daniel Okey-Okoro <danielokeyokoro at gmail.com>
Date: Thu, Aug 1, 2019 at 1:24 PM
Subject: Re: PEP: add a `no` keyword as an alias for `not`
To: Calvin Spealman <cspealma at redhat.com>


Good point Calvin,
------------------------------------------------------------
But in many cases, when people write `if not val` they're checking if the
val is `None`

i.e. `if val is None`, `if val == None`

(so in effect it's kind of like they're checking if "something isn't there")

I just did a code review. The idea popped in my head after reading code
that behaved this way.
-------------------------------------------------------------------
Plus, I'm suggesting an alias.

In some usecases it would be better to just use `if not val`.

i.e. in cases where you are strictly doing True/False assessments not
Falsey ( is_empty() ) assessments e.g. None, [], "", 0
```


Best Intentions,
Daniel Okey-Okoro

On Thu, Aug 1, 2019, 1:10 PM Calvin Spealman <cspealma at redhat.com> wrote:

> I think they actually read like they would mean slightly different things,
> which would make them existing as aliases confusing.
>
> I read `if not val` as "If val isn't true" but i would read `if no val` as
> "if val does not exist"
>
> On Thu, Aug 1, 2019 at 4:07 PM Daniel Okey-Okoro <
> danielokeyokoro at gmail.com> wrote:
>
>> I think that adding a `no` keyword as an alias for `not` would make for
>> more readable, simple, pythonic code.
>>
>> Take the below:
>>
>> ```
>> if not val:
>>   do_thing_because_value_is_falsy()
>> ```
>>
>> could be (is actually understood as):
>>
>> ```
>> if no val:
>>    do_thing_because_value_is_falsy()
>> ```
>>
>> I think this PEP is a work-around for an underlying subtle issue with how
>> the `not` operator is used.
>>
>> It has two use-cases:
>>
>> 1. as a NOT gate for producing opposite boolean values
>>
>> ```
>> opposite = not regular
>> ```
>>
>> 2. as a sort of  ".is_falsy()"  checker; when used with an if statement.
>>
>> like the first example.
>>
>>
>> This PEP would make the difference between the two usecases explicit.
>>
>> Thoughts?
>>
>> Best Intentions,
>> Daniel Okey-Okoro.
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
>
> --
>
> CALVIN SPEALMAN
>
> SENIOR QUALITY ENGINEER
>
> cspealma at redhat.com  M: +1.336.210.5107
> [image: https://red.ht/sig] <https://red.ht/sig>
> TRIED. TESTED. TRUSTED. <https://redhat.com/trusted>
>


-- 
Best Intentions,
Daniel Okey-Okoro.