False
should be expr is False
121 assert data['path'] == path
122 assert data['isDir'] == False
123 assert data['isFile'] == True
124 assert data['isLink'] == False125 assert data['mode'] == 0o100765
126 assert data['uid'] == os.stat(path).st_uid
127 assert data['gid'] == os.stat(path).st_gid
True
should be expr is True
120 assert data['name'] == 'file'
121 assert data['path'] == path
122 assert data['isDir'] == False
123 assert data['isFile'] == True124 assert data['isLink'] == False
125 assert data['mode'] == 0o100765
126 assert data['uid'] == os.stat(path).st_uid
False
should be expr is False
119 data = rq.json()
120 assert data['name'] == 'file'
121 assert data['path'] == path
122 assert data['isDir'] == False123 assert data['isFile'] == True
124 assert data['isLink'] == False
125 assert data['mode'] == 0o100765
False
should be expr is False
101 assert data[0]['path'] == path
102 assert data[0]['isDir'] == False
103 assert data[0]['isFile'] == True
104 assert data[0]['isLink'] == False105 assert data[0]['mode'] == 0o100765
106 assert data[0]['uid'] == os.stat(path).st_uid
107 assert data[0]['gid'] == os.stat(path).st_gid
True
should be expr is True
100 assert data[0]['name'] == 'file'
101 assert data[0]['path'] == path
102 assert data[0]['isDir'] == False
103 assert data[0]['isFile'] == True104 assert data[0]['isLink'] == False
105 assert data[0]['mode'] == 0o100765
106 assert data[0]['uid'] == os.stat(path).st_uid
Comparisons to the singleton objects, like True
, False
, and None
, should be done with identity, not equality. Use is
or is not
.
Identity checks are faster than equality checks.
Also, the equality checks can result in unintended behaviour in some cases:
>>> 1 is True
False
>>> 1 == True
True
>>> 1.0 is True
False
>>> 1.0 == True
True
value = fx()
if value == True: # `==` can cause unintended behaviour
print(value)
if value != None:
print(value)
value = fx()
if value is True: # `is` for Identity comparison
print(value)
if value is not None:
print(value)
Equality comparisons might be required in some cases, especially in SQLAlchemy, SQLObject, ORMs, etc. In these cases, it is safe to ignore this issue.