You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Providing more than one argument to Digraph subclass leads to exception in __new__ #8367
def test_child_graph():
> g1 = ChildGraph(1, 2, 'a')
^^^^^^^^^^^^^^^^^^^^^
E TypeError: DiGraph.__new__() takes from 1 to 2 positional arguments but 4 were given
Environment
Python version: 3.11
NetworkX version: 3.6
Additional context
Ubuntu 22.04, kernel 6.5, 6.8
Suggested fix
Add an *args argument to the __new__ method defined in the Digraph base class.
If instead the arguments beyond the first are provided as keyword arguments this behaves fine (b/c __new__ accepts **attrs ?). If only one argument is provided this behaves fine (b/c __new__ has one argument?)
This is caused due to the DiGraph class implementing __new__ method. To fix this, you should implement new in your subclass to match your init signature.
Is this something that was working for you and it recently broke?
or you can make the signature match the __init__ as @amcandio suggested.
Obviously not ideal, sorry. I/we know to be careful with user-defined graph classes, which is an important feature, but this mistake slipped through the cracks.
This won't be the first time I'm responsible for needing a hot-fix dot release 😶🌫️
This sounds like something we might want to fix and then make a 3.6.1 release.
Flagging for @MridulS
Agreed on the patch release (which we don't cover in the release guide!). I assume the easiest thing to do is create a 3.6.1-dev branch from the tagged 3.6.0 commit, cherry-pick the fix on that branch, then tag and go through the remaining release steps from there.
If cherry-picking for 3.6.1 is too messy, we could probably release from main. I don't think we have pushed anything that shouldn't be in 3.6.1. I think @jarrodmillman has done that in the past. (once we start updating deprecations and stuff like that then we wouldn't be able to do that of course...)
I think there is also the addition of spectral bipartition #8347. But that should not mess up any users. It is adding new functions.
I'm in favor of doing the 3.6.1 from main.
Activity
JEZiegler commentedon Dec 5, 2025
If instead the arguments beyond the first are provided as keyword arguments this behaves fine (b/c
__new__accepts **attrs ?). If only one argument is provided this behaves fine (b/c__new__has one argument?)amcandio commentedon Dec 5, 2025
This is caused due to the DiGraph class implementing
__new__method. To fix this, you should implement new in your subclass to match your init signature.Is this something that was working for you and it recently broke?
JEZiegler commentedon Dec 5, 2025
Yeah I already put this fix in but it looked somewhat like the
__new__implementation in Digraph was intended to be agnostic by accepting**attrs.Yes this was working before on older versions of networkx which makes sense given the
__new__implementation was added in 3.6 or so?amcandio commentedon Dec 5, 2025
Yes, it was caused by #7760 which we included in 3.6 release. Thanks for the report! cc: @eriknw
I don't have my laptop to test but hopefully changing
__new__in graph classes to take *arg and **kwarg might do it.dschult commentedon Dec 5, 2025
This sounds like something we might want to fix and then make a 3.6.1 release.
Flagging for @MridulS
Thanks for the report @JEZiegler !!
Fix: allow graph subclasses to have additional arguments
eriknw commentedon Dec 5, 2025
Oops, my bad! Hopefully fixed in #8369. Thanks for the ping @amcandio, and thanks all for the issue and discussion.
I think you can work around this issue in nx 3.6 by adding the following to your new class:
or you can make the signature match the
__init__as @amcandio suggested.Obviously not ideal, sorry. I/we know to be careful with user-defined graph classes, which is an important feature, but this mistake slipped through the cracks.
This won't be the first time I'm responsible for needing a hot-fix dot release 😶🌫️
amcandio commentedon Dec 5, 2025
Thanks for the quick turn around @eriknw!
rossbar commentedon Dec 5, 2025
Agreed on the patch release (which we don't cover in the release guide!). I assume the easiest thing to do is create a
3.6.1-devbranch from the tagged 3.6.0 commit, cherry-pick the fix on that branch, then tag and go through the remaining release steps from there.dschult commentedon Dec 6, 2025
If cherry-picking for 3.6.1 is too messy, we could probably release from main. I don't think we have pushed anything that shouldn't be in 3.6.1. I think @jarrodmillman has done that in the past. (once we start updating deprecations and stuff like that then we wouldn't be able to do that of course...)
MridulS commentedon Dec 6, 2025
I think it will be quicker just to do a 3.6.1 release from main, we only have doc and tests related PRs merged into main right now.
dschult commentedon Dec 7, 2025
I think there is also the addition of spectral bipartition #8347. But that should not mess up any users. It is adding new functions.
I'm in favor of doing the 3.6.1 from
main.⬆️ Resolve networkx python package 3.6 version issue. (facebookresear…
⬆️ Resolve networkx python package 3.6 version issue. (facebookresear…