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 7c4bf99
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@ name: tests
on: [push]

jobs:
test:
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
strategy:
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
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 7c4bf99

Please sign in to comment.