diff --git a/pyproject.toml b/pyproject.toml index 424a2d03..c7e5b8be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -272,3 +272,8 @@ showcontent = true pretty = true disallow_untyped_defs = true check_untyped_defs = true + + +[tool.pyright] +# We need epexrimental features for converters. +enableExperimentalFeatures = true diff --git a/tests/dataclass_transform_example.py b/tests/dataclass_transform_example.py index c65df140..fb28110e 100644 --- a/tests/dataclass_transform_example.py +++ b/tests/dataclass_transform_example.py @@ -15,7 +15,6 @@ reveal_type(Define.__init__) # noqa: F821 @attr.define() class DefineConverter: - # mypy plugin adapts the "int" method signature, pyright does not with_converter: int = attr.field(converter=int) diff --git a/tests/test_pyright.py b/tests/test_pyright.py index 800d6099..3f2bf89d 100644 --- a/tests/test_pyright.py +++ b/tests/test_pyright.py @@ -10,8 +10,6 @@ from pathlib import Path import pytest -import attrs - pytestmark = [ pytest.mark.skipif( @@ -20,21 +18,16 @@ pytestmark = [ ] -@attrs.frozen -class PyrightDiagnostic: - severity: str - message: str - - -def parse_pyright_output(test_file: Path) -> set[PyrightDiagnostic]: +def parse_pyright_output(test_file: Path) -> set[tuple[str, str]]: pyright = subprocess.run( # noqa: PLW1510 ["pyright", "--outputjson", str(test_file)], capture_output=True ) pyright_result = json.loads(pyright.stdout) + # We use tuples instead of proper classes to get nicer diffs from pytest. return { - PyrightDiagnostic(d["severity"], d["message"]) + (d["severity"], d["message"]) for d in pyright_result["generalDiagnostics"] } @@ -49,41 +42,40 @@ def test_pyright_baseline(): diagnostics = parse_pyright_output(test_file) - # Expected diagnostics as per pyright 1.1.311 expected_diagnostics = { - PyrightDiagnostic( - severity="information", - message='Type of "Define.__init__" is' - ' "(self: Define, a: str, b: int) -> None"', + ( + "information", + 'Type of "Define.__init__" is "(self: Define, a: str, b: int) -> None"', ), - PyrightDiagnostic( - severity="information", - message='Type of "DefineConverter.__init__" is ' + ( + "information", + 'Type of "DefineConverter.__init__" is ' '"(self: DefineConverter, with_converter: str | Buffer | ' 'SupportsInt | SupportsIndex | SupportsTrunc) -> None"', ), - PyrightDiagnostic( - severity="error", - message='Cannot assign member "a" for type ' - '"Frozen"\n\xa0\xa0"Frozen" is frozen\n\xa0\xa0\xa0\xa0Member "__set__" is unknown', + ( + "error", + 'Cannot assign to attribute "a" for class ' + '"Frozen"\n\xa0\xa0"Frozen" is frozen\n\xa0\xa0\xa0\xa0' + 'Attribute "__set__" is unknown', ), - PyrightDiagnostic( - severity="information", - message='Type of "d.a" is "Literal[\'new\']"', + ( + "information", + 'Type of "d.a" is "Literal[\'new\']"', ), - PyrightDiagnostic( - severity="error", - message='Cannot assign member "a" for type ' + ( + "error", + 'Cannot assign to attribute "a" for class ' '"FrozenDefine"\n\xa0\xa0"FrozenDefine" is frozen\n\xa0\xa0\xa0\xa0' - 'Member "__set__" is unknown', + 'Attribute "__set__" is unknown', ), - PyrightDiagnostic( - severity="information", - message='Type of "d2.a" is "Literal[\'new\']"', + ( + "information", + 'Type of "d2.a" is "Literal[\'new\']"', ), - PyrightDiagnostic( - severity="information", - message='Type of "af.__init__" is "(_a: int) -> None"', + ( + "information", + 'Type of "af.__init__" is "(_a: int) -> None"', ), } @@ -110,9 +102,9 @@ reveal_type(attrs.AttrsInstance) diagnostics = parse_pyright_output(test_pyright_attrsinstance_compat_path) expected_diagnostics = { - PyrightDiagnostic( - severity="information", - message='Type of "attrs.AttrsInstance" is "type[AttrsInstance]"', - ), + ( + "information", + 'Type of "attrs.AttrsInstance" is "type[AttrsInstance]"', + ) } assert diagnostics == expected_diagnostics diff --git a/tox.ini b/tox.ini index f6c94b4a..cafb068f 100644 --- a/tox.ini +++ b/tox.ini @@ -102,7 +102,7 @@ commands = towncrier build --version main --draft [testenv:pyright] extras = tests -deps = pyright<1.1.359 +deps = pyright commands = pytest tests/test_pyright.py -vv