[networkx] Some functions don't accept valid Graph types
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 5.1k
- Forks
- 2.1k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 82
Description
I'm using networkx with the Generics introduced by and think I have found a bug.
For some context:
I'm trying to run a type checker on a class Foo that looks like so:
class Bar(Mapping[str, Any]):
...
class Foo(Graph[int, Bar]):
node_attr_dict_factory = Bar
...
The key point being that Bar implements Mapping, but is not a dict.
networkx.draw(G: Graph[Node_], ...) doesn't accept this Foo graph, and gives a typing error with the current stubs.
In the transition to generic types for node and edge data, _NodeData and _EdgeData were given an upper bound of Mapping[str, Any] and a default of dict[str, Any]. (https://github.com/python/typeshed/pull/15660/changes)
With this, most functions that took a Graph[_Node] parameter before, were changed to take a Graph[_Node, _NodeData, _EdgeData]
However, some weren't changed, which means they effectively have a parameter with type: Graph[_Node, dict[str, Any], dict[str, Any].
Passing a Graph[_Node, Mapping[str, Any], dict[str, Any]] causes a type error.
Is there a reason that some functions weren't updated to use Graph[_Node, _NodeData, _EdgeData] @ThePiep ?
I see that there are a few other functions in the library that use Graph[_Node] still, but am unsure why.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez dans les stubs de networkx en recherchant les fonctions qui utilisent encore Graph[_Node] et comparez-les aux signatures mises à jour pour des données génériques de nœuds et d’arêtes. Vérifiez l’exemple Foo signalé avec un vérificateur de types, puis mettez à jour les signatures concernées afin que les données basées sur Mapping soient acceptées et vérifiez que l’erreur de typage est résolue.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- developer-experience, tooling
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- Active
- Clarté
- Plutôt claire
- Accessibilité débutants
- 68/100