Skip to content

Commit ddb0cda

Browse files
Update contribution guidelines around type annotations (#1063)
Since #1061 has merged rustworkx is now fully typed with mypy. This means that adding type annotations is no longer optional and is now required for all new function. This commit updates the contribution guidelines to indicate type annotations are required now. The details are also updated a bit to provide a bit more detail on what's required when adding type annotations to rustworkx. Co-authored-by: Ivan Carvalho <[email protected]>
1 parent 87cb008 commit ddb0cda

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

CONTRIBUTING.md

+28-6
Original file line numberDiff line numberDiff line change
@@ -274,19 +274,41 @@ cargo doc --open
274274
275275
### Type Annotations
276276
277-
If you have added new methods or changed method signatures, we encourage you to add annotations for
278-
those methods in stub files. The stub files are in the `rustworkx` directory and have a `.pyi` file extension.
279-
They contain annotated signatures for Python functions, stripped of their implementation.
280-
281-
While this step is optional, it is very helpful for end-users. Adding annotations lets users type check
282-
their code with [mypy](http://mypy-lang.org/), which can be helpful for finding bugs.
277+
If you have added new methods, functions, or classes, and/or changed any
278+
signatures, type anotations for Python are required to be included in a pull
279+
request. Type annotations are added using type
280+
[stub files](https://typing.readthedocs.io/en/latest/source/stubs.html) which
281+
provide type annotations to python tooling which use type annotations. The stub
282+
files are in the `rustworkx/` directory and have a `.pyi` file extension. They
283+
contain annotated signatures for Python functions, stripped of their
284+
implementation. You can find more details on typing in Python at:
285+
286+
* https://mypy.readthedocs.io/en/stable/
287+
* https://typing.readthedocs.io/en/latest/
288+
* https://docs.python.org/3/library/typing.html
289+
290+
Having type annotations is very helpful for Python end-users. Adding
291+
annotations lets users type check their code with [mypy](http://mypy-lang.org/),
292+
which can be helpful for finding bugs when using rustworkx.
283293
284294
Just like with tests for the code, annotations are also tested via tox.
285295
286296
```
287297
tox -estubs
288298
```
289299
300+
One important thing to note is that if you're adding a new function to the Rust
301+
module you will need to ensure that the signature with annotations is added to
302+
`rustworkx/rustworkx.pyi`. Then it is also necessary to re-export the annotation
303+
by adding an import line to `rustworkx/__init__.pyi` in the form:
304+
305+
```python
306+
from .rustworkx import foo as foo
307+
```
308+
309+
which ensures that mypy is able to find the type annotations when users import
310+
from the root `rustworkx` package (which is the most common access pattern).
311+
290312
### Release Notes
291313
292314
It is important to document any end user facing changes when we release a new

0 commit comments

Comments
 (0)