python / python/typeshed

[networkx] Some functions don't accept valid Graph types

Offen
#16,365 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stubs: false positive
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

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Ö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

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.