From 5d3fc6119be74a55f54b830efa8fb835bd991291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Thu, 17 Oct 2024 01:32:00 +0300 Subject: [PATCH] Added Pyright checking and fixed problems it found --- .github/workflows/test.yml | 17 +++++++++++++++++ pyproject.toml | 4 ++++ src/asphalt/core/_context.py | 2 +- src/asphalt/core/_utils.py | 4 ++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d4f0526d..4627f83d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,23 @@ on: pull_request: jobs: + pyright: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.x + - uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: pip-pyright + - name: Install dependencies + run: pip install -e . pyright + - name: Run pyright + run: pyright --verifytypes asphalt.core + test: strategy: fail-fast: false diff --git a/pyproject.toml b/pyproject.toml index befc87c5..cb4a5669 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,6 +113,10 @@ commands = [["python", "-m", "pytest", { replace = "posargs", extend = true }]] package = "editable" extras = ["test"] +[tool.tox.env.pyright] +deps = ["pyright"] +commands = [["pyright", "--verifytypes", "asphalt.core"]] + [tool.tox.env.docs] commands = [["sphinx-build", "-n", "docs", "build/sphinx", { replace = "posargs", extend = true }]] extras = ["doc"] diff --git a/src/asphalt/core/_context.py b/src/asphalt/core/_context.py index d86da7c8..aadc83d3 100644 --- a/src/asphalt/core/_context.py +++ b/src/asphalt/core/_context.py @@ -147,7 +147,7 @@ class Context: resource has been published in this context """ - resource_added = Signal(ResourceEvent) + resource_added: Signal[ResourceEvent] = Signal(ResourceEvent) _task_group: TaskGroup _reset_token: Token[Context] diff --git a/src/asphalt/core/_utils.py b/src/asphalt/core/_utils.py index 61bad7e6..2e19dd9f 100644 --- a/src/asphalt/core/_utils.py +++ b/src/asphalt/core/_utils.py @@ -121,8 +121,8 @@ class PluginContainer: __slots__ = "namespace", "base_class", "_entrypoints", "_resolved" def __init__(self, namespace: str, base_class: type | None = None) -> None: - self.namespace = namespace - self.base_class = base_class + self.namespace: str = namespace + self.base_class: type | None = base_class group = entry_points(group=namespace) self._entrypoints = {ep.name: ep for ep in group} self._resolved: dict[str, Any] = {}