python / python/typeshed

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

Abierto
#16,365 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stubs: false positive
Lenguaje dominante
Python
Estrellas
5.1k
Forks
2.1k
Merge medio
1 d 19 h
PR fusionados (30 d)
82

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza en los stubs de networkx localizando las funciones que todavía usan Graph[_Node] y compáralas con las firmas actualizadas para datos genéricos de nodos y aristas. Comprueba el ejemplo Foo reportado con un comprobador de tipos y, a continuación, actualiza las firmas relevantes para que se acepten datos basados en Mapping y verifica que el error de tipado se haya resuelto.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
developer-experience, tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
68/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.