Commit 931386d
committed
fix: Remove defensive checks in bipartite graph functions
This commit removes defensive checks in is_bipartite_dfs and is_bipartite_bfs functions that were preventing natural KeyError and TypeError exceptions from occurring for invalid graph inputs.
The functions contained checks like 'if node not in graph_node not in graph: return True' and 'if curr_node not in graph: continue' which would return early or skip processing when encountering invalid graph structures, instead of allowing the natural exceptions to occur.
According to FIXME comments in the docstrings, the expected behavior is:
- KeyError should be raised when a graph contains neighbors that are not keys in the graph dictionary
- TypeError should be raised when non-integer keys are used where integers are expected
By removing these defensive checks, the functions now properly raise KeyError when accessing graph[node] for a node that is not a key in the graph, which aligns with the documented expected behavior.
Fixes #151271 parent 181175e commit 931386d
1 file changed
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
72 | 70 | | |
73 | 71 | | |
74 | 72 | | |
| |||
140 | 138 | | |
141 | 139 | | |
142 | 140 | | |
143 | | - | |
144 | | - | |
145 | 141 | | |
146 | 142 | | |
147 | 143 | | |
| |||
0 commit comments