Reference

Chris Angelico rosuav at gmail.com
Tue Mar 4 09:06:20 EST 2014


On Tue, Mar 4, 2014 at 11:55 PM, Alexander Blinne <news at blinne.net> wrote:
> Am 03.03.2014 19:48, schrieb Terry Reedy:
>> The 'is' operator has three uses, two intended and one not. In
>> production code, 'is' tests that an object *is* a particular singular
>> object, such as None or a sentinel instance of class object.
>
> Just a bit of statistics on this one from a recent small project:
>
> <13:51:20> alex at firefly$ grep ' is ' *.py | wc
>      65     415    3234
> <13:51:35> alex at firefly$ grep ' is None' *.py | wc
>      43     243    1948
> <13:51:40> alex at firefly$ grep ' is not None' *.py | wc
>      21     167    1241
> <13:51:44> alex at firefly$ grep ' is False' *.py | wc
>       1       5      45
>
> No other uses if 'is' found in almost 3 KLOC...

Lemme spin you up a different way of doing it, which actually looks
for the operators.

https://github.com/Rosuav/ExceptExpr/blob/master/find_except_expr.py

Run across the Python stdlib, that tells me there are 4040 uses of
is/is not, of which 16 compare against False, 18 against True (see?
Python has a bias for truth above falsehood!), and 3386 against None.
The other 620 are probably mostly sentinel objects, but I didn't look
at them.

ChrisA



More information about the Python-list mailing list