@@ -6,7 +6,7 @@ from typing_extensions import TypeAlias, TypeVar
66from networkx .classes .coreviews import MultiAdjacencyView
77from networkx .classes .graph import Graph , _MapFactory , _Node
88from networkx .classes .multidigraph import MultiDiGraph
9- from networkx .classes .reportviews import MultiEdgeView
9+ from networkx .classes .reportviews import DiMultiDegreeView , MultiDegreeView , MultiEdgeView , OutMultiEdgeView
1010
1111_MultiEdge : TypeAlias = tuple [_Node , _Node , int ] # noqa: Y047
1212
@@ -15,36 +15,43 @@ _KeyT = TypeVar("_KeyT", bound=Hashable)
1515
1616__all__ = ["MultiGraph" ]
1717
18+ # NOTE: Graph subclasses relationships are so complex
19+ # we're only overriding methods that differ in signature from the base classes
20+ # to use inheritance to our advantage and reduce complexity
1821class MultiGraph (Graph [_Node ]):
1922 edge_key_dict_factory : ClassVar [_MapFactory ]
23+ def to_directed_class (self ) -> type [MultiDiGraph [_Node ]]: ...
24+ def to_undirected_class (self ) -> type [MultiGraph [_Node ]]: ...
2025 def __init__ (self , incoming_graph_data = None , multigraph_input : bool | None = None , ** attr : Any ) -> None : ...
2126 @cached_property
2227 def adj (self ) -> MultiAdjacencyView [_Node , _Node , dict [str , Any ]]: ... # data can be any type
2328 def new_edge_key (self , u : _Node , v : _Node ) -> int : ...
24- @overload # type: ignore[override] # Has an additional `key` keyword argument
29+ # key : hashable identifier, optional (default=lowest unused integer)
30+ @overload # type: ignore[override] # More complex overload
2531 def add_edge (self , u_for_edge : _Node , v_for_edge : _Node , key : int | None = None , ** attr : Any ) -> int : ...
2632 @overload
2733 def add_edge (self , u_for_edge : _Node , v_for_edge : _Node , key : _KeyT , ** attr : Any ) -> _KeyT : ...
28- # key : hashable identifier, optional (default=lowest unused integer)
2934 def remove_edge (self , u : _Node , v : _Node , key : Hashable | None = None ) -> None : ...
3035 def has_edge (self , u : _Node , v : _Node , key : Hashable | None = None ) -> bool : ...
36+ @cached_property
37+ # Including subtypes' possible return types for LSP
38+ def edges (self ) -> MultiEdgeView [_Node ] | OutMultiEdgeView [_Node ]: ...
39+ # key : hashable identifier, optional (default=None).
40+ # default : any Python object (default=None). Value to return if the specific edge (u, v, key) is not found.
41+ # Returns: The edge attribute dictionary.
3142 @overload # type: ignore[override]
3243 def get_edge_data (
3344 self , u : _Node , v : _Node , key : Hashable , default : _DefaultT | None = None
3445 ) -> dict [str , Any ] | _DefaultT : ...
35- # key : hashable identifier, optional (default=None).
36- # default : any Python object (default=None). Value to return if the specific edge (u, v, key) is not found.
37- # Returns: The edge attribute dictionary.
46+ # default : any Python object (default=None). Value to return if there are no edges between u and v and no key is specified.
47+ # Returns: A dictionary mapping edge keys to attribute dictionaries for each of those edges if no specific key is provided.
3848 @overload
3949 def get_edge_data (
4050 self , u : _Node , v : _Node , key : None = None , default : _DefaultT | None = None
4151 ) -> dict [Hashable , dict [str , Any ] | _DefaultT ]: ...
42- # default : any Python object (default=None). Value to return if there are no edges between u and v and no key is specified.
43- # Returns: A dictionary mapping edge keys to attribute dictionaries for each of those edges if no specific key is provided.
4452 def copy (self , as_view : bool = False ) -> MultiGraph [_Node ]: ...
53+ @cached_property
54+ # Including subtypes' possible return types for LSP
55+ def degree (self ) -> MultiDegreeView [_Node ] | DiMultiDegreeView [_Node ]: ...
4556 def to_directed (self , as_view : bool = False ) -> MultiDiGraph [_Node ]: ...
4657 def to_undirected (self , as_view : bool = False ) -> MultiGraph [_Node ]: ...
47- def number_of_edges (self , u : _Node | None = None , v : _Node | None = None ) -> int : ...
48- @cached_property
49- def edges (self ) -> MultiEdgeView [_Node ]: ... # type: ignore[override]
50- # Returns: MultiEdgeView
0 commit comments