Skip to content

API: Deprecate p2g module - #8855

Merged
MridulS merged 11 commits into
networkx:mainfrom
rossbar:deprecate-p2g
Aug 21, 2026
Merged

MridulS merged 11 commits into
networkx:mainfrom
rossbar:deprecate-p2g

Conversation

@rossbar

@rossbar rossbar commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Closes #8195

Deprecates the entire p2g module (see linked discussion for motivation) by raising on import. In this case, this works because the p2g module is excluded from the __all__ hierarchy, so it is not picked up by the lazy load machinery, nor is it pulled in with the top level import.

I ended up going down a pretty deep rabbit hole in trying to test that deprecation warning gets raised. The situation is trickier than usual due to import caching. What's here works but is quite involved - if folks wanted I'd be just as happy to leave the deprecated warnings testing out!

@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.

This all looks good to me -- import cruft is readable, and not too long. Lets leave it in if only to have a record of what you did.... but also because it will be used until v3.9

:)

Comment thread networkx/conftest.py
)
warnings.filterwarnings(
"ignore", category=DeprecationWarning, message="The p2g module"
)

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.

huh, for some reason I thought we raise warnings as errors for our pytest runs in CI. But that isn't true.

Anyway running pytest with --doctest-modules will import pg2 before running the fixture so it shows up in the pytest output.

.pixi/envs/default/lib/python3.13/importlib/__init__.py:88: 10 warnings
  /Users/mridulseth/dev/networkx/.pixi/envs/default/lib/python3.13/importlib/__init__.py:88: DeprecationWarning: The p2g module is deprecated and will be removed in v3.9
    return _bootstrap._gcd_import(name[level:], package, level)

I guess we should just remove the pg2 file from pytest collection with something like?

collect_ignore = ["readwrite/p2g.py"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup I noticed that too - and was peeved that the warnings filter wasn't catching it (it makes sense though since it was from doctest itself!) +1 for adding to collect_ignore!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just tried locally and unfortunately the collect_ignore strategy doesn't work "/. I'd just as soon remove the tests themselves!

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.

Yeah lets remove them :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops - it looks like I misdiagnosed the problem. It's not the added tests and the module-cache-munging that causes the problem, but simply the fact that the --doctest-modules flag causes an import of all modules. So - this is the problem we have to fix. It's too bad the warnings filter in conftest doesn't pick this up, but I guess it all depends on order-of-operations.

So - we need a different solution!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just tried locally and unfortunately the collect_ignore strategy doesn't work "/. I'd just as soon remove the tests themselves!

Nevermind - collect_ignore works fine - I got confused by the other warnings in the summary. After a rebase (with all the other pytest warnings fixed) I noticed these had disappeared too :)

@MridulS
MridulS merged commit cfc6b79 into networkx:main Aug 21, 2026
43 checks passed
@dschult dschult added this to the 3.7 milestone Aug 21, 2026
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.

p2g module does not lazy-load

3 participants