Ticket #2473 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

[with patch, positive review] BipartiteGraph.__init__ does not properly initialize for some inputs

Reported by: rhinton Owned by: rlm
Priority: major Milestone: sage-2.10.4
Component: graph theory Keywords:
Cc: Work issues:
Report Upstream: Reviewers:
Authors: Merged in:
Dependencies: Stopgaps:

Description

BipartiteGraph.init does not call the base class init for some inputs, leaving the object unusable. For example,

sage: B = BipartiteGraph(None)
sage: B

will throw an exception because the base class attributes have not been initialized. The attached patch ensures the base class init is called.

Attachments

bipartite_graph_input.patch Download (4.3 KB) - added by rhinton 5 years ago.
bipartite_graph_input.2.patch Download (5.3 KB) - added by rhinton 5 years ago.
try #2
2473-ref.patch Download (4.5 KB) - added by rlm 5 years ago.
Apply bipartite_graph_input.2.patch, then this.

Change History

comment:1 Changed 5 years ago by rlm

  • Summary changed from [with patch, needs review] BipartiteGraph.__init__ does not properly initialize for some inputs to [with patch, negative review] BipartiteGraph.__init__ does not properly initialize for some inputs

The problem with this approach is it allows one to construct graphs which are not bipartite, but they will be instances of BipartiteGraph?. What should be done instead is to raise a NotImplementedError?, so that the user knows that the initialization failed. This problem is a small part of the much bigger task in ticket #1941, which is one of the next things I'll be doing. Watch for a patch in the next few days, perhaps...

Changed 5 years ago by rhinton

Changed 5 years ago by rhinton

try #2

comment:2 Changed 5 years ago by rhinton

  • Summary changed from [with patch, negative review] BipartiteGraph.__init__ does not properly initialize for some inputs to [with patch, needs review] BipartiteGraph.__init__ does not properly initialize for some inputs

The updated patch, I believe, addresses your concerns. It also fixes several more bugs.

comment:3 Changed 5 years ago by rlm

Is patch 2 supposed to replace patch 1?

comment:4 Changed 5 years ago by rlm

Some notes:

  1. "TESTS" should actually be labeled "EXAMPLE" or "EXAMPLES". This is just the convention.
  1. Comments in the examples don't need "#"; see many other doctests for examples of the formatting.
  1. I've moved the networkx import further down so it only happens if it needs to. This import, if it hasn't been done before, takes several seconds... (I know this doesn't seem to make much sense now, but soon we won't be importing networkx by default whenever we have a graph, so it will make sense eventually.)

Changed 5 years ago by rlm

Apply bipartite_graph_input.2.patch, then this.

comment:5 Changed 5 years ago by rlm

  • Summary changed from [with patch, needs review] BipartiteGraph.__init__ does not properly initialize for some inputs to [with patch, positive review] BipartiteGraph.__init__ does not properly initialize for some inputs
  • Milestone changed from sage-2.11 to sage-2.10.4

comment:6 Changed 5 years ago by mabshoff

  • Status changed from new to closed
  • Resolution set to fixed

Merged in Sage 2.10.4.alpha0

Note: See TracTickets for help on using tickets.