Skip to content

Ensure that backend names are valid Python identifiers - #8160

Merged
MridulS merged 2 commits into
networkx:mainfrom
eriknw:backend_name_valid_identifier
Jul 22, 2025
Merged

MridulS merged 2 commits into
networkx:mainfrom
eriknw:backend_name_valid_identifier

Conversation

@eriknw

@eriknw eriknw commented Jul 21, 2025

Copy link
Copy Markdown
Contributor

In #8115, a user encountered an error when a backend name was not a valid Python identifier.

@amcandio suggested we guard against this #8115 (comment).

Notably, it's possible for users to encounter this when e.g. networkx.egg-info/entry_points.txt file has an old entry for nx-loopback instead of nx_loopback, as may have happened in #8115.

This PR ignores backends that are not valid identifiers, displays a warning when this happens, and updates documentation to indicate that backends must be valid Python identifiers.

Instead of checking when creating the config as suggested in #8115 (comment), this PR checks when loading the entry points for backends.

If an invalidly named backend uses both networkx.backends and networkx.backend_info entry points, two warnings will be issued.

@amcandio amcandio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! Left a minor suggestion but this looks good to me

Comment thread networkx/utils/backends.py Resolved
@rossbar rossbar added Dispatching Related to dispatching and backend support type: Bug fix labels Jul 22, 2025

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks @eriknw ! This sounds like a reasonable hypothesis for what went wrong in #8115 and if that's the case, this patch should prevent it from happening in the future. It'd be nice to test as well but we can leave that for a followup.

@MridulS
MridulS merged commit ad37990 into networkx:main Jul 22, 2025
@MridulS MridulS added this to the 3.6 milestone Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dispatching Related to dispatching and backend support type: Bug fix

Development

Successfully merging this pull request may close these issues.

4 participants