Skip to content

Commit b8330b2

Browse files
Fix unreachable code issue by restructuring method execution order
1 parent 760ea13 commit b8330b2

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

pydatastructs/graphs/graph.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ def __new__(cls, *args, **kwargs):
7575
cls, kwargs.get('backend', Backend.PYTHON))
7676
default_impl = args[0]._impl if args else 'adjacency_list'
7777
implementation = kwargs.get('implementation', default_impl)
78+
if implementation == 'adjacency_list':
79+
from pydatastructs.graphs.adjacency_list import AdjacencyList
80+
obj = AdjacencyList(*args)
81+
obj._impl = implementation
82+
83+
elif implementation == 'adjacency_matrix':
84+
from pydatastructs.graphs.adjacency_matrix import AdjacencyMatrix
85+
obj = AdjacencyMatrix(*args)
86+
obj._impl = implementation
87+
88+
else:
89+
raise NotImplementedError("%s implementation is not a part "
90+
"of the library currently."%(implementation))
7891
obj._impl = implementation
7992
obj.snapshots = {}
8093

@@ -97,21 +110,7 @@ def list_snapshots(self):
97110
obj.add_snapshot = add_snapshot.__get__(obj)
98111
obj.get_snapshot = get_snapshot.__get__(obj)
99112
obj.list_snapshots = list_snapshots.__get__(obj)
100-
101-
102-
if implementation == 'adjacency_list':
103-
from pydatastructs.graphs.adjacency_list import AdjacencyList
104-
obj = AdjacencyList(*args)
105-
obj._impl = implementation
106-
return obj
107-
elif implementation == 'adjacency_matrix':
108-
from pydatastructs.graphs.adjacency_matrix import AdjacencyMatrix
109-
obj = AdjacencyMatrix(*args)
110-
obj._impl = implementation
111-
return obj
112-
else:
113-
raise NotImplementedError("%s implementation is not a part "
114-
"of the library currently."%(implementation))
113+
return obj
115114

116115

117116
def is_adjacent(self, node1, node2):

0 commit comments

Comments
 (0)