Skip to content

Commit 2ad2459

Browse files
authored
Document running type checkers (#614)
* pyproject: Configure mypy and pyright Signed-off-by: Philipp Hahn <[email protected]> * hacking-guide: Document type checkers Signed-off-by: Philipp Hahn <[email protected]> --------- Signed-off-by: Philipp Hahn <[email protected]>
1 parent 037a5ee commit 2ad2459

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@ MANIFEST
1010
*.egg-info
1111
.vscode
1212
temp
13-
14-
15-
16-
13+
mypy.junit.xml
14+
mypy/

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ recursive-include examples *.py *.elf *.out
44
recursive-include test *
55
global-exclude *.py[cod]
66
global-exclude __pycache__
7+
global-exclude .mypy_cache
78
include README.rst
89
include LICENSE
910
include CHANGES

doc/hacking-guide.rst

+22
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.

pyproject.toml

+20
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ Homepage = "https://github.com/eliben/pyelftools"
4242
Repository = "https://github.com/eliben/pyelftools.git"
4343
Issues = "https://github.com/eliben/pyelftools/issues"
4444

45+
[dependency-groups]
46+
typing = ["mypy[reports]", "pyright", "typeguard"]
47+
4548
[tool.setuptools]
4649
packages = [
4750
"elftools",
@@ -64,3 +67,20 @@ version = {attr = "elftools.__version__"}
6467

6568
[tool.setuptools.package-data]
6669
elftools = ["py.types"]
70+
71+
[tool.mypy]
72+
error_summary = false
73+
disallow_any_generics = true
74+
disallow_untyped_defs = true
75+
disallow_incomplete_defs = true
76+
warn_redundant_casts = true
77+
warn_unused_ignores = true
78+
# html_report = "mypy"
79+
packages = "elftools"
80+
# junit_xml = "mypy.junit.xml"
81+
junit_format = "per_file"
82+
83+
[tool.pyright]
84+
include = [
85+
"elftools",
86+
]

0 commit comments

Comments
 (0)