rustworkx icon indicating copy to clipboard operation
rustworkx copied to clipboard

Problem type checking `ancestors()` with pyright

Open jlhamilton777 opened this issue 7 months ago • 3 comments

Information

  • rustworkx version: 0.15.1
  • Python version: 3.12.4
  • Rust version: 1.79.0
  • Operating system: Void Linux x86_64

What is the current behavior?

Pyright is unable to fully type check the rustworkx.ancestors() function in strict mode.

What is the expected behavior?

Pyright should be able to determine the type of ancestors(), including the parameterized type of the graph parameter.

Steps to reproduce the problem

# pyright: strict

import rustworkx as rx

graph: rx.PyDiGraph[int, float] = rx.PyDiGraph()
node = graph.add_node(7)
rx.ancestors(graph, node)
$ pyright .
./main.py
  ./main.py:7:1 - error: Type of "ancestors" is partially unknown
    Type of "ancestors" is "(graph: PyDiGraph[Unknown, Unknown], node: int, /) -> set[int]" (reportUnknownMemberType)
1 error, 0 warnings, 0 informations

I looked at the stub file https://github.com/Qiskit/rustworkx/blob/553bff1823a30293c82fb811f4457b094700a728/rustworkx/rustworkx.pyi#L985-L990 and graph doesn't have PyDiGraph[_S, _T] like in some of the other functions. I also ran into this issue with the descendants() function.

jlhamilton777 avatar Jul 05 '24 02:07 jlhamilton777