Skip to content

Commit

Permalink
Finalize type signatures and enforce for all future functions (#1061)
Browse files Browse the repository at this point in the history
* Finalize type signatures and enforce for all future functions

This commit adds the last few missing type hints (primarily the
generators module) and switches the CI configuration over to enforce
that the library is completely type hinted. This makes it a CI error if
a function or method is added that doesn't include type hints. This is
all built on the hard work of @IvanIsCoding who built up all the type
hinting infrastructure and stub files for the majority of rustworkx.
This is just the last piece to enforce the library is fully typed moving
forward.

Co-authored-by: Ivan Carvalho <ivancarv@student.ubc.ca>

* Fix lint

* Add missing stubs and run on full package

* Fix to_dot() and graphviz_draw() hints

* Fix lint

* Fix search function hints

* Fix full package stubtest

This commit fixes most of the package for stubtest to work. This
primarily involves having the stubfiles match the package layout.
Unfortunately this means we need to put the majority of the type hints
in the stubfile for `rustworkx.rustworkx`. Having the stubfiles split up
as before mypy complains that the module doesn't exist. For example,
having the coloring functions in `rustworkx/coloring.pyi` causes a mypy
error that `rustworkx.coloring` couldn't be imported. This causes the
rustworkx.pyi file to be quite large, but I couldn't find a pattern
to workaround this limitation. Aside from that a bunch of stubs needed
to be updated as now that they're getting included in the stubtest run
issues were caught. The one exception is the generators module where the
custom `text_signature` set in the function definitions were incorrect
and tripping up mypy, these were fixed by removing the `text_signature`
fields.

* Ignore matplotlib type checks

* Add back type hints lost during rebase

* Add stub file for matplotlib visualization

* Bump mypy version used in tests

* Add stub file for graphviz too

* Fix last failure

* Fix typo

* Use typing_extensions for mpl_draw type hints

* Add re-exports to root __init__.pyi

This commit adds back the re-exports to the root `__init__.pyi` stub file.
As was reported in #960 the manual re-exports are necessary to ensure
that mypy can find symbols in the root of the package, where most people
use them, instead of off the inner `rustworkx.rustworkx` module.

* Add release note

* Add type check ignore to mpl for 3.8 failures

* Fix release note typo

---------

Co-authored-by: Ivan Carvalho <ivancarv@student.ubc.ca>
  • Loading branch information
mtreinish and IvanIsCoding committed Jan 21, 2024
1 parent 6931377 commit 5344f68
Show file tree
Hide file tree
Showing 35 changed files with 1,810 additions and 1,921 deletions.
7 changes: 7 additions & 0 deletions releasenotes/notes/fully-typed-0fbab79a7206d7e3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
features:
- |
The ``rustworkx`` Python package is now fully typed with
`mypy <https://mypy-lang.org/>`__. Building off of the previous 0.13.0
release which introduced partial type annotations to the library, rustworkx
now includes type annotations for the entire public API.
391 changes: 208 additions & 183 deletions rustworkx/__init__.pyi

Large diffs are not rendered by default.

25 changes: 0 additions & 25 deletions rustworkx/cartesian_product.pyi

This file was deleted.

90 changes: 0 additions & 90 deletions rustworkx/centrality.pyi

This file was deleted.

21 changes: 0 additions & 21 deletions rustworkx/coloring.pyi

This file was deleted.

107 changes: 0 additions & 107 deletions rustworkx/connectivity.pyi

This file was deleted.

59 changes: 0 additions & 59 deletions rustworkx/dag_algo.pyi

This file was deleted.

0 comments on commit 5344f68

Please sign in to comment.