Skip to content

Commit a2a8cd6

Browse files
committed
hacking-guide: Document type checkers
Signed-off-by: Philipp Hahn <[email protected]>
1 parent 0142daf commit a2a8cd6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

doc/hacking-guide.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,26 @@ Coding conventions
6565
**pyelftools** is written in Python, following the `PEP 8 <http://www.python.org/dev/peps/pep-0008/>`_ style guide.
6666

6767

68+
Type checking
69+
-------------
6870

71+
**pyelftools** is using and providing Type Hints, following the `PEP 484 <https://peps.python.org/pep-0484/>`_.
72+
Please make sure new functions and methods are properly type hinted.
73+
There are some known limitations as **pyelftools** is dynamic for some types, which does not work well for _static typing_.
74+
75+
Please make sure to run [pyright](https://github.com/microsoft/pyright) and/or [mypy](https://mypy.readthedocs.io/en/stable/) on your contributions.
76+
For this Python 3.12 (or newer) is required:
77+
78+
.. sourcecode:: text
79+
80+
> uv sync --dev --group typing --python 3.12
81+
> . .venv/bin/activate
82+
> pyright
83+
> mypy
84+
85+
You can also install ``pyright`` or ``mypy`` globally and (re-)use them for multiple projects:
86+
87+
1. either install them once with ``uv tool install -p 3.12 pyright`` respective ``uv tool install -p 3.12 mypy``. Afterwards you can directly invoke ``pyright`` or ``mypy``.
88+
2. or run them from a temporary VENV each time by using ``uv tool run -p 3.12 pyright`` respective ``uv tool run -p 3.12 mypy``.
89+
90+
Compared to the recommendation above this has the drawback that (in the future) type hints for external dependencies might be missing.

0 commit comments

Comments
 (0)