Skip to content

Commit 227dbb8

Browse files
committed
Fix all 'Testing equality to None' issues
Testing whether an object is `None` using the `==` operator is inefficient and potentially incorrect. This PR has substituted all instances (that are not subject to be regenerated by exp2python) with`is None`
1 parent 69db0c0 commit 227dbb8

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/exp2python/python/SCL/AggregationDataTypes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def __getitem__(self, index):
179179
raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index))
180180
else:
181181
value = self._container[index-self._bound_1]
182-
if not self._optional and value==None:
182+
if not self._optional and value is None:
183183
raise AssertionError("Not OPTIONAL prevent the value with index %i from being None (default). Please set the value first."%index)
184184
return value
185185

@@ -239,7 +239,7 @@ def __init__( self , bound_1 , bound_2 , base_type , UNIQUE = False, scope = No
239239
raise TypeError("LIST lower bound must be an integer")
240240
# bound_2 can be set to None
241241
self._unbounded = False
242-
if bound_2 == None:
242+
if bound_2 is None:
243243
self._unbounded = True
244244
elif not isinstance(bound_2, int):
245245
raise TypeError("LIST upper bound must be an integer")
@@ -313,7 +313,7 @@ def __getitem__(self, index):
313313
raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index))
314314
else:
315315
value = self._container[index-self._bound_1]
316-
if value == None:
316+
if value is None:
317317
raise AssertionError("Value with index %i not defined. Please set the value first."%index)
318318
return value
319319
#case unbounded
@@ -322,7 +322,7 @@ def __getitem__(self, index):
322322
raise AssertionError("Value with index %i not defined. Please set the value first."%index)
323323
else:
324324
value = self._container[index-self._bound_1]
325-
if value == None:
325+
if value is None:
326326
raise AssertionError("Value with index %i not defined. Please set the value first."%index)
327327
return value
328328

@@ -413,7 +413,7 @@ def __init__( self , bound_1 , bound_2 , base_type , scope = None):
413413
raise TypeError("LIST lower bound must be an integer")
414414
# bound_2 can be set to None
415415
self._unbounded = False
416-
if bound_2 == None:
416+
if bound_2 is None:
417417
self._unbounded = True
418418
elif not isinstance(bound_2, int):
419419
raise TypeError("LIST upper bound must be an integer")
@@ -531,7 +531,7 @@ def __init__( self , bound_1 , bound_2 , base_type , scope = None):
531531
raise TypeError("LIST lower bound must be an integer")
532532
# bound_2 can be set to None
533533
self._unbounded = False
534-
if bound_2 == None:
534+
if bound_2 is None:
535535
self._unbounded = True
536536
elif not isinstance(bound_2, int):
537537
raise TypeError("LIST upper bound must be an integer")

src/exp2python/python/SCL/BaseType.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def get_scope(self):
4545

4646
def get_type(self):
4747
if isinstance(self._typedef, str):
48-
if self._scope == None:
48+
if self._scope is None:
4949
raise AssertionError('No scope defined for this type')
5050
elif self._typedef in vars(self._scope):
5151
return vars(self._scope)[self._typedef]

src/exp2python/python/SCL/Builtin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def SIN(V):
220220
#Result : true or false depending on whether V has an actual or indeterminate (?) value.
221221
#EXAMPLE 131 { IF EXISTS ( a ) THEN ...
222222
def EXISTS(V):
223-
if V==None:
223+
if V is None:
224224
return False
225225
else:
226226
return True

0 commit comments

Comments
 (0)