Skip to content

Commit 0559e52

Browse files
committed
Use typing module for exactly one purpose
Add pyright to the lint tasks. Configure pyright in pyproject.toml. Signed-off-by: mulhern <[email protected]>
1 parent df1b576 commit 0559e52

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

.github/workflows/main.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ jobs:
2121
- dependencies: yamllint
2222
task: make -f Makefile yamllint
2323
- dependencies: >
24+
bandit
2425
pylint
2526
python3-dbus
2627
python3-dbus-signature-pyparsing
2728
python3-hypothesis
2829
task: >
29-
PYTHONPATH=./src:/github/home/.local/lib/python3.12/site-packages
30-
make -f Makefile lint
30+
PATH=${PATH}:/github/home/.local/bin
31+
PYTHONPATH=./src make -f Makefile lint
3132
- dependencies: >
3233
python3-dbus
3334
python3-dbus-signature-pyparsing
@@ -53,6 +54,8 @@ jobs:
5354
${{ matrix.dependencies }}
5455
- name: Install hs-dbus-signature
5556
run: pip install --user hs-dbus-signature
57+
- name: Install pyright
58+
run: pip install --user pyright
5659
- name: ${{ matrix.task }}
5760
run: ${{ matrix.task }}
5861

@@ -61,12 +64,15 @@ jobs:
6164
matrix:
6265
include:
6366
- dependencies: >
67+
bandit
6468
pylint
6569
python3-dbus
6670
python3-dbus-signature-pyparsing
6771
python3-hypothesis
6872
python3-hs-dbus-signature
69-
task: PYTHONPATH=./src make -f Makefile lint
73+
task: >
74+
PATH=${PATH}:/github/home/.local/bin
75+
PYTHONPATH=./src make -f Makefile lint
7076
- dependencies: >
7177
python3-dbus
7278
python3-dbus-signature-pyparsing
@@ -90,6 +96,9 @@ jobs:
9096
run: >
9197
dnf install -y
9298
make
99+
pip
93100
${{ matrix.dependencies }}
101+
- name: Install pyright
102+
run: pip install --user pyright
94103
- name: ${{ matrix.task }}
95104
run: ${{ matrix.task }}

.github/workflows/weekly.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ jobs:
1717
- dependencies: yamllint
1818
task: make -f Makefile yamllint
1919
- dependencies: >
20+
bandit
2021
pylint
2122
python3-dbus
2223
python3-dbus-signature-pyparsing
2324
python-hypothesis
2425
task: >
25-
PYTHONPATH=./src:/github/home/.local/lib/python3.12/site-packages
26-
make -f Makefile lint
26+
PATH=${PATH}:/github/home/.local/bin
27+
PYTHONPATH=./src make -f Makefile lint
2728
runs-on: ubuntu-latest
2829
container: fedora:41 # NEXT DEVELOPMENT ENVIRONMENT
2930
steps:
@@ -36,5 +37,7 @@ jobs:
3637
${{ matrix.dependencies }}
3738
- name: Install hs-dbus-signature
3839
run: pip install --user hs-dbus-signature
40+
- name: Install pyright
41+
run: pip install --user pyright
3942
- name: ${{ matrix.task }}
4043
run: ${{ matrix.task }}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ lint:
33
pylint setup.py
44
pylint src/into_dbus_python
55
pylint tests
6+
bandit setup.py
7+
bandit --recursive ./src
8+
bandit --recursive ./tests
9+
pyright
610

711
.PHONY: test
812
test:

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[build-system]
22
requires = ["setuptools"]
33
build-backend = "setuptools.build_meta"
4+
5+
[tool.pyright]
6+
include = ["src"]

src/into_dbus_python/_xformer.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# isort: STDLIB
1919
import functools
2020
from collections.abc import Sequence
21+
from typing import Any
2122

2223
# isort: THIRDPARTY
2324
import dbus
@@ -148,7 +149,7 @@ def the_dict_func(a_dict, *, variant=0):
148149
if len(toks) == 2:
149150
(func, sig) = toks[1]
150151

151-
def the_array_func(a_list, *, variant=0):
152+
def the_array_func(a_list: Sequence[Any], *, variant=0):
152153
"""
153154
Function for generating an Array from a list.
154155
@@ -188,7 +189,7 @@ def _handle_struct(toks):
188189
signature = "".join(s for (_, s) in subtrees)
189190
funcs = [f for (f, _) in subtrees]
190191

191-
def the_func(a_list, *, variant=0):
192+
def the_func(a_list: Sequence[Any], *, variant=0):
192193
"""
193194
Function for generating a Struct from a list.
194195
@@ -290,9 +291,13 @@ def __init__(self):
290291

291292
self.VARIANT.setParseAction(self._handle_variant)
292293

293-
self.ARRAY.setParseAction(_ToDbusXformer._handle_array)
294+
self.ARRAY.setParseAction( # pyright: ignore [ reportOptionalMemberAccess ]
295+
_ToDbusXformer._handle_array
296+
)
294297

295-
self.STRUCT.setParseAction(_ToDbusXformer._handle_struct)
298+
self.STRUCT.setParseAction( # pyright: ignore [ reportOptionalMemberAccess ]
299+
_ToDbusXformer._handle_struct
300+
)
296301

297302

298303
_XFORMER = _ToDbusXformer()

0 commit comments

Comments
 (0)