Skip to content

Proposal to deprecate bfs_predecessors - #8494

Merged
dschult merged 5 commits into
networkx:mainfrom
rossbar:deprecate-bfs-preds
Feb 15, 2026
Merged

dschult merged 5 commits into
networkx:mainfrom
rossbar:deprecate-bfs-preds

Conversation

@rossbar

@rossbar rossbar commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

Inspired by #8445

The term "predecessor" in bfs_predecessors has a different meaning than it does in the rest of the library in the context of directed graphs. This has led to confusion (see #8445 and other linked issues there).

The docstring has been clarified, but it's worth noting that bfs_predecessors is a one-liner that essentially wraps bfs_edges. Therefore, I propose to deprecated bfs_predecessors in favor of the direct call to bfs_edges. This reduces the API surface related to bfs, as well as removes the point of confusion with respect to terminology.

FWIW I also looked at bfs_successors, but that is a more involved generator and is (IMO) quite useful, thus is not a good target for deprecation.

@Peiffap Peiffap left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this deprecation makes sense. FYI, GitHub finds about 180 uses of nx.bfs_predecessors in existing repositories.

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rossbar!!
(And @Peiffap for the review)

@dschult
dschult merged commit c2bb296 into networkx:main Feb 15, 2026
38 checks passed
@dschult dschult added this to the 3.7 milestone Feb 15, 2026
@rossbar
rossbar deleted the deprecate-bfs-preds branch February 15, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants