ENH: Add support for hiding edges for callable capacity or weight parameter
Author: gulshan-123Created Jan 9, 2026Updated Jan 9, 2026
Current Behavior
G = nx.DiGraph()
G.add_edge(0, 1, weight=1)
G.add_edge(1, 2, weight=2)
def myweight(u, v, e_attr):
if u == 0 and v == 1:
return e_attr['weight']
else:
return None
nx.bellman_ford_predecessor_and_distance(G, source=0, weight=myweight)throws TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
Expected Behavior
In most of the algorithms like dijkstra, floyd_warshall, if the capacity/weight function returns None, then that edge is assumed to be hidden.
It is not currently supported in bellman_ford. We also need to find if there are other such functions, where the parameter can be weight/capacity function but hiding an edge is not supported.
Additional context
Comments in #8440 https://github.com/networkx/networkx/pull/8440#issuecomment-3721614854
Source: networkx/networkx