diff --git a/.github/workflows/base.yml b/.github/workflows/base.yml index f840478..56d6619 100644 --- a/.github/workflows/base.yml +++ b/.github/workflows/base.yml @@ -48,6 +48,14 @@ jobs: steps: - uses: actions/checkout@v2 + # Install pyright + - uses: actions/setup-node@v2 + with: + node-version: '16' + + - name: Install pyright + run: npm install -g pyright@1.1.223 + # Conda install - name: Install conda v3.7 uses: conda-incubator/setup-miniconda@v2 diff --git a/setup.cfg b/setup.cfg index ff0a6d7..5dd4126 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,12 +35,14 @@ setup_requires = pytest-runner install_requires = makefun>=1.5.0 + typing_extensions;python_version>='3.6' # note: do not use double quotes in these, this triggers a weird bug in PyCharm in debug mode only funcsigs;python_version<'3.3' enum34;python_version<'3.4' tests_require = pytest pytest_cases + syrupy;python_version>'3.6' # for some reason these pytest dependencies were not declared in old versions of pytest six;python_version<'3.6' attr;python_version<'3.6' diff --git a/src/decopatch/main.pyi b/src/decopatch/main.pyi index 8649211..1dd410d 100644 --- a/src/decopatch/main.pyi +++ b/src/decopatch/main.pyi @@ -1,13 +1,10 @@ from typing import Any, Callable, Optional, Protocol, TypeVar, overload +from typing_extensions import ParamSpec + from decopatch.utils_disambiguation import FirstArgDisambiguation from decopatch.utils_modes import SignatureInfo -try: - from typing import ParamSpec -except ImportError: - from typing_extensions import ParamSpec - P = ParamSpec("P") F = TypeVar("F", bound=Callable[..., Any]) diff --git a/tests/pyright/__init__.py b/tests/pyright/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/pyright/__snapshots__/test_typing.ambr b/tests/pyright/__snapshots__/test_typing.ambr new file mode 100644 index 0000000..1df0c00 --- /dev/null +++ b/tests/pyright/__snapshots__/test_typing.ambr @@ -0,0 +1,40 @@ +# name: test_typing + [ + { + 'message': ' + No overloads for "function_decorator" match the provided arguments +   Argument types: (Literal[True]) + ', + 'range': { + 'end': { + 'character': 47, + 'line': 10, + }, + 'start': { + 'character': 9, + 'line': 10, + }, + }, + 'rule': 'reportGeneralTypeIssues', + 'severity': 'error', + }, + { + 'message': ' + Argument of type "Literal[2]" cannot be assigned to parameter "scope" of type "str" in function "__call__" +   "Literal[2]" is incompatible with "str" + ', + 'range': { + 'end': { + 'character': 26, + 'line': 30, + }, + 'start': { + 'character': 25, + 'line': 30, + }, + }, + 'rule': 'reportGeneralTypeIssues', + 'severity': 'error', + }, + ] +--- diff --git a/tests/pyright/base.py b/tests/pyright/base.py new file mode 100644 index 0000000..71015cc --- /dev/null +++ b/tests/pyright/base.py @@ -0,0 +1,18 @@ +import json +import subprocess + + +def run_pyright(filename): + result = subprocess.run( + ["pyright", "--outputjson", filename], + capture_output=True, + text=True, + ) + assert result.stdout, result.stderr + output = json.loads(result.stdout) + + def clean_row(data): + del data["file"] + return data + + return [clean_row(row) for row in output["generalDiagnostics"]] diff --git a/tests/test_typing.py b/tests/pyright/test_file.py similarity index 86% rename from tests/test_typing.py rename to tests/pyright/test_file.py index 9fbb395..ce791c1 100644 --- a/tests/test_typing.py +++ b/tests/pyright/test_file.py @@ -1,6 +1,3 @@ -# This is test file for typing, -# No automatic testing is used at the moment. Just use your type checker and see if it works. -# Pytest here is used to make sure that runtime behavir matches with type checker expecter errors. from typing import Any, Callable import pytest diff --git a/tests/pyright/test_typing.py b/tests/pyright/test_typing.py new file mode 100644 index 0000000..b3ee190 --- /dev/null +++ b/tests/pyright/test_typing.py @@ -0,0 +1,12 @@ +import pytest +import sys +from .base import run_pyright + + +@pytest.mark.skipif( + sys.version_info < (3, 7), + reason="Requires Python 3.7+", +) +def test_typing(snapshot): + actual = run_pyright("tests/pyright/test_file.py") + assert actual == snapshot