Skip to content

Commit 6e25a0c

Browse files
authored
Unpin/fix Pyright (#1302)
* Unpin/fix Pyright Fixes #1278 * Consistency * Remove stale comment * Add explanation why we need experimental features
1 parent 6f64cd6 commit 6e25a0c

File tree

4 files changed

+37
-41
lines changed

4 files changed

+37
-41
lines changed

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,8 @@ showcontent = true
272272
pretty = true
273273
disallow_untyped_defs = true
274274
check_untyped_defs = true
275+
276+
277+
[tool.pyright]
278+
# We need epexrimental features for converters.
279+
enableExperimentalFeatures = true

tests/dataclass_transform_example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class Define:
1515

1616
@attr.define()
1717
class DefineConverter:
18-
# mypy plugin adapts the "int" method signature, pyright does not
1918
with_converter: int = attr.field(converter=int)
2019

2120

tests/test_pyright.py

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
import pytest
1212

13-
import attrs
14-
1513

1614
pytestmark = [
1715
pytest.mark.skipif(
@@ -20,21 +18,16 @@
2018
]
2119

2220

23-
@attrs.frozen
24-
class PyrightDiagnostic:
25-
severity: str
26-
message: str
27-
28-
29-
def parse_pyright_output(test_file: Path) -> set[PyrightDiagnostic]:
21+
def parse_pyright_output(test_file: Path) -> set[tuple[str, str]]:
3022
pyright = subprocess.run( # noqa: PLW1510
3123
["pyright", "--outputjson", str(test_file)], capture_output=True
3224
)
3325

3426
pyright_result = json.loads(pyright.stdout)
3527

28+
# We use tuples instead of proper classes to get nicer diffs from pytest.
3629
return {
37-
PyrightDiagnostic(d["severity"], d["message"])
30+
(d["severity"], d["message"])
3831
for d in pyright_result["generalDiagnostics"]
3932
}
4033

@@ -49,41 +42,40 @@ def test_pyright_baseline():
4942

5043
diagnostics = parse_pyright_output(test_file)
5144

52-
# Expected diagnostics as per pyright 1.1.311
5345
expected_diagnostics = {
54-
PyrightDiagnostic(
55-
severity="information",
56-
message='Type of "Define.__init__" is'
57-
' "(self: Define, a: str, b: int) -> None"',
46+
(
47+
"information",
48+
'Type of "Define.__init__" is "(self: Define, a: str, b: int) -> None"',
5849
),
59-
PyrightDiagnostic(
60-
severity="information",
61-
message='Type of "DefineConverter.__init__" is '
50+
(
51+
"information",
52+
'Type of "DefineConverter.__init__" is '
6253
'"(self: DefineConverter, with_converter: str | Buffer | '
6354
'SupportsInt | SupportsIndex | SupportsTrunc) -> None"',
6455
),
65-
PyrightDiagnostic(
66-
severity="error",
67-
message='Cannot assign member "a" for type '
68-
'"Frozen"\n\xa0\xa0"Frozen" is frozen\n\xa0\xa0\xa0\xa0Member "__set__" is unknown',
56+
(
57+
"error",
58+
'Cannot assign to attribute "a" for class '
59+
'"Frozen"\n\xa0\xa0"Frozen" is frozen\n\xa0\xa0\xa0\xa0'
60+
'Attribute "__set__" is unknown',
6961
),
70-
PyrightDiagnostic(
71-
severity="information",
72-
message='Type of "d.a" is "Literal[\'new\']"',
62+
(
63+
"information",
64+
'Type of "d.a" is "Literal[\'new\']"',
7365
),
74-
PyrightDiagnostic(
75-
severity="error",
76-
message='Cannot assign member "a" for type '
66+
(
67+
"error",
68+
'Cannot assign to attribute "a" for class '
7769
'"FrozenDefine"\n\xa0\xa0"FrozenDefine" is frozen\n\xa0\xa0\xa0\xa0'
78-
'Member "__set__" is unknown',
70+
'Attribute "__set__" is unknown',
7971
),
80-
PyrightDiagnostic(
81-
severity="information",
82-
message='Type of "d2.a" is "Literal[\'new\']"',
72+
(
73+
"information",
74+
'Type of "d2.a" is "Literal[\'new\']"',
8375
),
84-
PyrightDiagnostic(
85-
severity="information",
86-
message='Type of "af.__init__" is "(_a: int) -> None"',
76+
(
77+
"information",
78+
'Type of "af.__init__" is "(_a: int) -> None"',
8779
),
8880
}
8981

@@ -110,9 +102,9 @@ def test_pyright_attrsinstance_compat(tmp_path):
110102

111103
diagnostics = parse_pyright_output(test_pyright_attrsinstance_compat_path)
112104
expected_diagnostics = {
113-
PyrightDiagnostic(
114-
severity="information",
115-
message='Type of "attrs.AttrsInstance" is "type[AttrsInstance]"',
116-
),
105+
(
106+
"information",
107+
'Type of "attrs.AttrsInstance" is "type[AttrsInstance]"',
108+
)
117109
}
118110
assert diagnostics == expected_diagnostics

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ commands = towncrier build --version main --draft
102102

103103
[testenv:pyright]
104104
extras = tests
105-
deps = pyright<1.1.359
105+
deps = pyright
106106
commands = pytest tests/test_pyright.py -vv
107107

108108

0 commit comments

Comments
 (0)