Skip to content

Use typing module in exactly one place #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ jobs:
- dependencies: yamllint
task: make -f Makefile yamllint
- dependencies: >
bandit
pylint
python3-dbus
python3-dbus-signature-pyparsing
python3-hypothesis
task: >
PYTHONPATH=./src:/github/home/.local/lib/python3.12/site-packages
make -f Makefile lint
PATH=${PATH}:/github/home/.local/bin
PYTHONPATH=./src make -f Makefile lint
- dependencies: >
python3-dbus
python3-dbus-signature-pyparsing
Expand All @@ -53,6 +54,8 @@ jobs:
${{ matrix.dependencies }}
- name: Install hs-dbus-signature
run: pip install --user hs-dbus-signature
- name: Install pyright
run: pip install --user pyright
- name: ${{ matrix.task }}
run: ${{ matrix.task }}

Expand All @@ -61,12 +64,15 @@ jobs:
matrix:
include:
- dependencies: >
bandit
pylint
python3-dbus
python3-dbus-signature-pyparsing
python3-hypothesis
python3-hs-dbus-signature
task: PYTHONPATH=./src make -f Makefile lint
task: >
PATH=${PATH}:/github/home/.local/bin
PYTHONPATH=./src make -f Makefile lint
- dependencies: >
python3-dbus
python3-dbus-signature-pyparsing
Expand All @@ -90,6 +96,9 @@ jobs:
run: >
dnf install -y
make
pip
${{ matrix.dependencies }}
- name: Install pyright
run: pip install --user pyright
- name: ${{ matrix.task }}
run: ${{ matrix.task }}
7 changes: 5 additions & 2 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ jobs:
- dependencies: yamllint
task: make -f Makefile yamllint
- dependencies: >
bandit
pylint
python3-dbus
python3-dbus-signature-pyparsing
python-hypothesis
task: >
PYTHONPATH=./src:/github/home/.local/lib/python3.12/site-packages
make -f Makefile lint
PATH=${PATH}:/github/home/.local/bin
PYTHONPATH=./src make -f Makefile lint
runs-on: ubuntu-latest
container: fedora:41 # NEXT DEVELOPMENT ENVIRONMENT
steps:
Expand All @@ -36,5 +37,7 @@ jobs:
${{ matrix.dependencies }}
- name: Install hs-dbus-signature
run: pip install --user hs-dbus-signature
- name: Install pyright
run: pip install --user pyright
- name: ${{ matrix.task }}
run: ${{ matrix.task }}
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ lint:
pylint setup.py
pylint src/into_dbus_python
pylint tests
bandit setup.py
# Ignore B101 errors. We do not distribute optimized code, i.e., .pyo
# files in Fedora, so we do not need to have concerns that assertions
# are removed by optimization.
bandit --recursive ./src --skip B101
bandit --recursive ./tests
pyright

.PHONY: test
test:
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.pyright]
include = ["src"]
13 changes: 9 additions & 4 deletions src/into_dbus_python/_xformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# isort: STDLIB
import functools
from collections.abc import Sequence
from typing import Any

# isort: THIRDPARTY
import dbus
Expand Down Expand Up @@ -148,7 +149,7 @@ def the_dict_func(a_dict, *, variant=0):
if len(toks) == 2:
(func, sig) = toks[1]

def the_array_func(a_list, *, variant=0):
def the_array_func(a_list: Sequence[Any], *, variant=0):
"""
Function for generating an Array from a list.

Expand Down Expand Up @@ -188,7 +189,7 @@ def _handle_struct(toks):
signature = "".join(s for (_, s) in subtrees)
funcs = [f for (f, _) in subtrees]

def the_func(a_list, *, variant=0):
def the_func(a_list: Sequence[Any], *, variant=0):
"""
Function for generating a Struct from a list.

Expand Down Expand Up @@ -290,9 +291,13 @@ def __init__(self):

self.VARIANT.setParseAction(self._handle_variant)

self.ARRAY.setParseAction(_ToDbusXformer._handle_array)
self.ARRAY.setParseAction( # pyright: ignore [ reportOptionalMemberAccess ]
_ToDbusXformer._handle_array
)

self.STRUCT.setParseAction(_ToDbusXformer._handle_struct)
self.STRUCT.setParseAction( # pyright: ignore [ reportOptionalMemberAccess ]
_ToDbusXformer._handle_struct
)


_XFORMER = _ToDbusXformer()
Expand Down
Loading