None
should be expr is None
460 return totalcost
461
462 def canBeExtended(self, max_cost=None):
463 if max_cost == None:464 max_cost = self.max_cost
465 return self.cost() < max_cost
466
None
should be expr is not None
279
280 def copy(self):
281 gdgtCpy = GadgetMatrix(self.arch)
282 if self.chainCond != None:283 gdgtCpy.chainCond = self.chainCond.copy()
284 gdgtCpy.matrix = self.matrix.copy()
285 gdgtCpy.inst = self.inst
None
should be expr is None
267 instMatrix = self.lookupFromCache(inst)
268
269 # init chain cond or update
270 if self.chainCond == None:271 self.initChainCond(inst)
272 else:
273 # TODO: Hypothesis no side effect on chainInst
None
should be expr is None
216
217 def initChainCond(self, chainInst):
218
219 if self.inst == None:220 self.inst = chainInst
221 self.matrix = sparse.identity(self.arch.size, dtype=bool).tocsr()
222 # groups = chainInst.groups
None
should be expr is not None
211 self.nbrInsts = 0
212 self.nbrBytes = 0
213
214 if chainInst != None:215 self.addInst(chainInst)
216
217 def initChainCond(self, chainInst):
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.