Skip to content

Commit ac78b7d

Browse files
committed
python/ci: add Python type check
We started to use more and more type hints in our Python code, especially in most helper functions. This change doesn't force you to write type hints to every Python code, but enforces correct type hints when they are already provided. Typings are a great developer experience improvement in IDEs with Python support. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
1 parent d32b12b commit ac78b7d

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
run: nix build -L .#checks.x86_64-linux.pythonFormat
4040
- name: Check Python Lints
4141
run: nix build -L .#checks.x86_64-linux.pythonLint
42+
- name: Check Python Types
43+
run: nix build -L .#checks.x86_64-linux.pythonTypes
4244
- name: Check Spelling
4345
run: nix build -L .#checks.x86_64-linux.typos
4446
# Run all in case we forgot to add a fine-grained job.
@@ -47,7 +49,6 @@ jobs:
4749
nix build -L .#checks.x86_64-linux.all
4850
# Run all other flake-wide checks
4951
# TODO add once we have quicker CI runners
50-
# This
5152
# nix flake check
5253
- name: Eval Default Test Suite
5354
run: nix eval -L .#tests.x86_64-linux.default.driver

flake.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@
141141
ruff check ./tests
142142
mkdir $out
143143
'';
144+
pythonTypes =
145+
pkgs.runCommand "python-types"
146+
{
147+
nativeBuildInputs = with pkgs; [ pyright ];
148+
}
149+
''
150+
pyright ${cleanSrc}/tests
151+
mkdir $out
152+
'';
144153
typos =
145154
pkgs.runCommand "spellcheck"
146155
{
@@ -167,6 +176,7 @@
167176
deadnix
168177
pythonFormat
169178
pythonLint
179+
pythonTypes
170180
typos
171181
;
172182
default = all;

tests/testscript.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import unittest
77
import weakref
88

9+
# pyright: reportPossiblyUnboundVariable=false
10+
911
# Following is required to allow proper linting of the python code in IDEs.
1012
# Because certain functions like start_all() and certain objects like computeVM
1113
# or other machines are added by Nix, we need to provide certain stub objects
@@ -85,7 +87,8 @@ def __init__(self, command, machine):
8587
:param machine: Virtual machine to send the command from
8688
:type machine: Machine
8789
"""
88-
self._finilizer = weakref.finalize(self, command, machine)
90+
91+
self._finilizer = weakref.finalize(self, command, machine) # pyright: ignore[reportCallIssue]
8992

9093
def __enter__(self):
9194
return self

tests/testscript_long_migration_with_load.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import time
22
import unittest
33

4+
# pyright: reportPossiblyUnboundVariable=false
5+
46
# Following is required to allow proper linting of the python code in IDEs.
57
# Because certain functions like start_all() and certain objects like computeVM
68
# or other machines are added by Nix, we need to provide certain stub objects

0 commit comments

Comments
 (0)