Skip to content

Commit

Permalink
Add pyright to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Apr 25, 2024
1 parent 5f33f2a commit 34d4c8e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 4 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ name: tests
on: [push]

jobs:
typecheck:
name: Run typechecking with pyright
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install uv
uv pip sync --system requirements/requirements.txt requirements/requirements-test.txt
- name: Run pyright
run: pyright

test:
name: Run tests with pytest
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ classifiers = [
license = {file = "LICENSE"}
requires-python = ">=3.8"
dependencies = [
"typing-extensions>=4.0.1; python_version < '3.10'",
"typing-extensions>=4.10.0; python_version < '3.13'",
]

[tool.setuptools]
Expand Down
1 change: 1 addition & 0 deletions requirements/requirements-dev.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-c requirements.txt
pyright
ruff
7 changes: 7 additions & 0 deletions requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@
#
# pip-compile requirements/requirements-dev.in
#
nodeenv==1.8.0
# via pyright
pyright==1.1.360
# via -r requirements/requirements-dev.in
ruff==0.3.2
# via -r requirements/requirements-dev.in

# The following packages are considered to be unsafe in a requirements file:
# setuptools
1 change: 1 addition & 0 deletions requirements/requirements-test.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-c requirements.txt
pyright
pytest
tomli
tox
Expand Down
7 changes: 7 additions & 0 deletions requirements/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ filelock==3.13.1
# virtualenv
iniconfig==2.0.0
# via pytest
nodeenv==1.8.0
# via pyright
packaging==24.0
# via
# pyproject-api
Expand All @@ -33,6 +35,8 @@ pluggy==1.4.0
# tox
pyproject-api==1.6.1
# via tox
pyright==1.1.360
# via -r requirements/requirements-test.in
pytest==8.1.1
# via -r requirements/requirements-test.in
tomli==2.0.1
Expand All @@ -45,3 +49,6 @@ tox-gh-actions==3.2.0
# via -r requirements/requirements-test.in
virtualenv==20.25.1
# via tox

# The following packages are considered to be unsafe in a requirements file:
# setuptools
6 changes: 3 additions & 3 deletions src/jsonlogic/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class JSONLogicExpression:
expression: JSONLogicPrimitive | NormalizedExpression

@classmethod
def from_json(cls, json: JSON) -> Self: # TODO disallow list?
def from_json(cls, json: JSON) -> Self: # TODO disallow list? TODO fix type errors
"""Build a JSON Logic expression from JSON data.
Operator arguments are recursively normalized to a :class:`list`::
Expand All @@ -90,15 +90,15 @@ def from_json(cls, json: JSON) -> Self: # TODO disallow list?
assert expr.expression == {"var": ["varname"]}
"""
if not isinstance(json, dict):
return cls(expression=json)
return cls(expression=json) # type: ignore

operator, op_args = next(iter(json.items()))
if not isinstance(op_args, list):
op_args = [op_args]

sub_expressions = [cls.from_json(op_arg) for op_arg in op_args]

return cls({operator: sub_expressions})
return cls({operator: sub_expressions}) # type: ignore

def as_operator_tree(self, operator_registry: OperatorRegistry) -> JSONLogicPrimitive | Operator:
"""Return a recursive tree of operators, using the provided registry as a reference.
Expand Down

0 comments on commit 34d4c8e

Please sign in to comment.