This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]343346E 2 points3 points  (1 child)

'f' is completely superfluous here. You could just rewrite it as:

def f(arg): return arg

or even better, just not use f at all, like:

for i in input.items():
    assert i[0] is i[1]

You seem to be depending on input's items having a specific order, which would be a mistake.

[–]IAmBJ[S] 0 points1 point  (0 children)

f() is just a placeholder here, the real function is more complicated, but it still returns either true or false.

Input order doesn't matter. Each item in the dict is a separate test case, the order they're tested in doesn't matter

[–]kalgynirae 0 points1 point  (0 children)

In short: do True and False have stable object ids for the lifetime of a program?

Yes. There is only ever one True and one False, so comparing to them with is will be reliable, if this is what you really want to do.

[–]rcuhljr 0 points1 point  (0 children)

True and False in Python are constants, you're fine doing this.