Skip to content

Commit 15ab8ba

Browse files
Saptashrungiczgdp1807
authored andcommitted
Use comparison by reference for bool type objects (#66)
1 parent 27d3ed8 commit 15ab8ba

File tree

6 files changed

+100
-100
lines changed

6 files changed

+100
-100
lines changed

pydatastructs/linear_data_structures/arrays.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class OneDimensionalArray(Array):
6666
__slots__ = ['_size', '_data', '_dtype']
6767

6868
def __new__(cls, dtype=NoneType, *args, **kwargs):
69-
if dtype == NoneType or len(args) not in (1, 2):
69+
if dtype is NoneType or len(args) not in (1, 2):
7070
raise ValueError("1D array cannot be created due to incorrect"
7171
" information.")
7272
obj = object.__new__(cls)
@@ -206,7 +206,7 @@ class DynamicOneDimensionalArray(DynamicArray, OneDimensionalArray):
206206
def __new__(cls, dtype=NoneType, *args, **kwargs):
207207
obj = super().__new__(cls, dtype, *args, **kwargs)
208208
obj._load_factor = float(kwargs.get('load_factor', 0.25))
209-
obj._num = 0 if obj._size == 0 or obj[0] == None else obj._size
209+
obj._num = 0 if obj._size == 0 or obj[0] is None else obj._size
210210
obj._last_pos_filled = obj._num - 1
211211
return obj
212212

@@ -219,7 +219,7 @@ def _modify(self):
219219
arr_new = ODA(self._dtype, 2*self._num + 1)
220220
j = 0
221221
for i in range(self._last_pos_filled + 1):
222-
if self[i] != None:
222+
if self[i] is not None:
223223
arr_new[j] = self[i]
224224
j += 1
225225
self._last_pos_filled = j - 1
@@ -244,7 +244,7 @@ def append(self, el):
244244

245245
def delete(self, idx):
246246
if idx <= self._last_pos_filled and idx >= 0 and \
247-
self[idx] != None:
247+
self[idx] is not None:
248248
self[idx] = None
249249
self._num -= 1
250250
if self._last_pos_filled == idx:
@@ -270,16 +270,16 @@ def _modify(self):
270270
arr_new = OneDimensionalArray(self._dtype, 2*self._num + 1)
271271
j = 0
272272
for i in range(self._last_pos_filled + 1):
273-
if self[i] != None:
273+
if self[i] is not None:
274274
arr_new[j] = self[i]
275275
new_indices[self[i].key] = j
276276
j += 1
277277
for i in range(j):
278-
if arr_new[i].left != None:
278+
if arr_new[i].left is not None:
279279
arr_new[i].left = new_indices[self[arr_new[i].left].key]
280-
if arr_new[i].right != None:
280+
if arr_new[i].right is not None:
281281
arr_new[i].right = new_indices[self[arr_new[i].right].key]
282-
if arr_new[i].parent != None:
282+
if arr_new[i].parent is not None:
283283
arr_new[i].parent = new_indices[self[arr_new[i].parent].key]
284284
self._last_pos_filled = j - 1
285285
self._data = arr_new._data

pydatastructs/miscellaneous_data_structures/stack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __new__(cls, maxsize=None, top=0, items=None, dtype=int):
8989
raise ValueError("maxsize is missing.")
9090
if not _check_type(top, int):
9191
raise TypeError("top is not of type int.")
92-
if items == None:
92+
if items is None:
9393
items = OneDimensionalArray(dtype, maxsize)
9494
if not _check_type(items, OneDimensionalArray):
9595
raise ValueError("items is not of type, OneDimensionalArray")

0 commit comments

Comments
 (0)