[Python-Dev] Proposed unittest changes
Tim Peters
tim.peters at gmail.com
Mon Jul 14 02:32:12 CEST 2008
[Michael Foord]
>> ...
>> Adding the following new asserts:
>>
>> ...
>> assertNotIs (first, second, msg=None)
[Steve Holden]
> Please, let's call this one "assertIsNot".
+1
> I know it's valid Python to say
>
> if a not is b:
Nope, that's a syntax error.
> but it's a much less natural way of expressing the condition, and (for all I
> know) might even introduce an extra negation operation. "is not" is, I
> believe, treated as a single operator.
"is not" and "not in" are both binary infix operators, not to be
confused with the distinct use of "not" on its own as a unary prefix
operator. "not is" and "in not" are both gibberish.
>>> 1 is not 2
True
>>> 1 is (not 2)
False
>>> 1 not is 2
SyntaxError: invalid syntax
>>> 1 not in [2]
True
>>> 1 in not [2]
SyntaxError: invalid syntax
>>> 1 in (not [2])
Traceback (most recent call last):
...
TypeError: argument of type 'bool' is not iterable
More information about the Python-Dev
mailing list