11"""Conversion functions from Python types to internal igraph types."""
22
3+ from __future__ import annotations
4+
35import numpy as np
4- import numpy .typing as npt
56
67from ctypes import memmove , POINTER
7- from typing import Any , Iterable , List , Optional , Sequence
8+ from typing import Any , Iterable , List , Optional , Sequence , TYPE_CHECKING
89
910from .enums import MatrixStorage
1011from .lib import (
7071from .utils import bytes_to_str
7172from .wrappers import (
7273 _EdgeSelector ,
73- _Graph ,
7474 _Matrix ,
7575 _MatrixInt ,
7676 _Vector ,
8181 _VertexSelector ,
8282)
8383
84+ if TYPE_CHECKING :
85+ from igraph_ctypes .graph import Graph
86+
87+
8488__all__ = (
8589 "any_to_igraph_bool_t" ,
8690 "bytes_to_str" ,
@@ -145,9 +149,7 @@ def edgelike_to_igraph_integer_t(edge: EdgeLike) -> igraph_integer_t:
145149 raise ValueError (f"{ edge !r} cannot be converted to an igraph edge index" )
146150
147151
148- def edge_selector_to_igraph_es_t (
149- selector : EdgeSelector , graph : _Graph
150- ) -> _EdgeSelector :
152+ def edge_selector_to_igraph_es_t (selector : EdgeSelector , graph : Graph ) -> _EdgeSelector :
151153 """Converts a Python object representing a selection of edges to an
152154 igraph_es_t object.
153155 """
@@ -166,15 +168,15 @@ def edge_selector_to_igraph_es_t(
166168 return _EdgeSelector .create_with (igraph_es_1 , index )
167169
168170
169- def edge_weights_to_igraph_vector_t (weights : Iterable [float ], graph : _Graph ) -> _Vector :
171+ def edge_weights_to_igraph_vector_t (weights : Iterable [float ], graph : Graph ) -> _Vector :
170172 """Converts a Python iterable of floating-point numbers to a vector of
171173 edge weights.
172174 """
173175 return iterable_to_igraph_vector_t (weights )
174176
175177
176178def edge_weights_to_igraph_vector_t_view (
177- weights : Optional [Iterable [float ]], graph : _Graph
179+ weights : Optional [Iterable [float ]], graph : Graph
178180) -> Optional [_Vector ]:
179181 """Converts a Python iterable of floating-point numbers to a vector of
180182 edge weights, possibly creating a shallow view if the input is an
@@ -198,13 +200,13 @@ def edge_weights_to_igraph_vector_t_view(
198200edge_capacities_to_igraph_vector_t_view = edge_weights_to_igraph_vector_t_view
199201
200202
201- def edge_colors_to_igraph_vector_t (colors : Iterable [int ], graph : _Graph ) -> _VectorInt :
203+ def edge_colors_to_igraph_vector_t (colors : Iterable [int ], graph : Graph ) -> _VectorInt :
202204 """Converts a Python iterable of integers to a vector of edge colors."""
203205 return iterable_to_igraph_vector_int_t (colors )
204206
205207
206208def edge_colors_to_igraph_vector_t_view (
207- colors : Iterable [int ], graph : _Graph
209+ colors : Iterable [int ], graph : Graph
208210) -> _VectorInt :
209211 """Converts a Python iterable of integers to a vector of edge colors,
210212 possibly creating a shallow view if the input is an appropriate NumPy array.
@@ -596,7 +598,7 @@ def vertex_pairs_to_igraph_vector_int_t(pairs: Iterable[VertexPair]) -> _VectorI
596598
597599
598600def vertex_selector_to_igraph_vs_t (
599- selector : VertexSelector , graph : _Graph
601+ selector : VertexSelector , graph : Graph
600602) -> _VertexSelector :
601603 """Converts a Python object representing a selection of vertices to an
602604 igraph_vs_t object.
@@ -609,38 +611,38 @@ def vertex_selector_to_igraph_vs_t(
609611 # TODO(ntamas): implement name lookup?
610612 raise TypeError ("vertex selector cannot be a string" )
611613 elif hasattr (selector , "__iter__" ):
612- indices = iterable_vertex_indices_to_igraph_vector_int_t (selector ) # type: ignore
614+ indices = iterable_vertex_indices_to_igraph_vector_int_t (
615+ selector # type: ignore
616+ )
613617 return _VertexSelector .create_with (igraph_vs_vector_copy , indices )
614618 else :
615619 index = vertexlike_to_igraph_integer_t (selector ) # type: ignore
616620 return _VertexSelector .create_with (igraph_vs_1 , index )
617621
618622
619- def vertex_colors_to_igraph_vector_t (
620- colors : Iterable [int ], graph : _Graph
621- ) -> _VectorInt :
623+ def vertex_colors_to_igraph_vector_t (colors : Iterable [int ], graph : Graph ) -> _VectorInt :
622624 """Converts a Python iterable of integers to a vector of vertex colors."""
623625 return iterable_to_igraph_vector_int_t (colors )
624626
625627
626628def vertex_colors_to_igraph_vector_t_view (
627- colors : Iterable [int ], graph : _Graph
629+ colors : Iterable [int ], graph : Graph
628630) -> _VectorInt :
629631 """Converts a Python iterable of integers to a vector of vertex colors,
630632 possibly creating a shallow view if the input is an appropriate NumPy array.
631633 """
632634 return iterable_to_igraph_vector_int_t_view (colors )
633635
634636
635- def vertex_qtys_to_igraph_vector_t (weights : Iterable [float ], graph : _Graph ) -> _Vector :
637+ def vertex_qtys_to_igraph_vector_t (weights : Iterable [float ], graph : Graph ) -> _Vector :
636638 """Converts a Python iterable of floating-point numbers to a vector of
637639 vertex-related quantities.
638640 """
639641 return iterable_to_igraph_vector_t (weights )
640642
641643
642644def vertex_qtys_to_igraph_vector_t_view (
643- weights : Optional [Iterable [float ]], graph : _Graph
645+ weights : Optional [Iterable [float ]], graph : Graph
644646) -> Optional [_Vector ]:
645647 """Converts a Python iterable of floating-point numbers to a vector of
646648 vertex-related quantities, possibly creating a shallow view if the input is
0 commit comments