[networkx] Some functions don't accept valid Graph types
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 5.1k
- Forks
- 2.1k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 82
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in den networkx-Stubs, indem du Funktionen suchst, die noch Graph[_Node] verwenden, und vergleiche sie mit Signaturen, die für generische Knoten- und Kantendaten aktualisiert wurden. Überprüfe das gemeldete Foo-Beispiel mit einem Typprüfer und aktualisiere dann die relevanten Signaturen, sodass Mapping-basierte Daten akzeptiert werden, und verifiziere, dass der Typfehler behoben ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- developer-experience, tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 68/100