Skip to content

Commit 2b3a427

Browse files
authored
Fix pyright for 1.1.311 (#1138)
They support converters now!
1 parent a6778cf commit 2b3a427

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

docs/types.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ class SomeClass:
8989
:::{warning}
9090
The *Pyright* inferred types are a tiny subset of those supported by *Mypy*, including:
9191

92-
- The generated `__init__` signature only includes the attribute type annotations.
93-
It currently does not include attribute `converter` types.
94-
9592
- The `attrs.frozen` decorator is not typed with frozen attributes, which are properly typed via `attrs.define(frozen=True)`.
9693

9794
Your constructive feedback is welcome in both [attrs#795](https://github.com/python-attrs/attrs/issues/795) and [pyright#1782](https://github.com/microsoft/pyright/discussions/1782).

tests/dataclass_transform_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class DefineConverter:
2121

2222
reveal_type(DefineConverter.__init__) # noqa
2323

24+
DefineConverter(with_converter=b"42")
25+
2426

2527
@attr.frozen()
2628
class Frozen:

tests/test_pyright.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# SPDX-License-Identifier: MIT
22

3+
from __future__ import annotations
4+
35
import json
4-
import os.path
56
import shutil
67
import subprocess
78

9+
from pathlib import Path
10+
811
import pytest
912

1013
import attrs
@@ -23,7 +26,7 @@ class PyrightDiagnostic:
2326
message: str
2427

2528

26-
def parse_pyright_output(test_file):
29+
def parse_pyright_output(test_file: Path) -> set[PyrightDiagnostic]:
2730
pyright = subprocess.run(
2831
["pyright", "--outputjson", str(test_file)], capture_output=True
2932
)
@@ -42,11 +45,11 @@ def test_pyright_baseline():
4245
decorated class types.
4346
"""
4447

45-
test_file = os.path.dirname(__file__) + "/dataclass_transform_example.py"
48+
test_file = Path(__file__).parent / "dataclass_transform_example.py"
4649

4750
diagnostics = parse_pyright_output(test_file)
4851

49-
# Expected diagnostics as per pyright 1.1.135
52+
# Expected diagnostics as per pyright 1.1.311
5053
expected_diagnostics = {
5154
PyrightDiagnostic(
5255
severity="information",
@@ -55,8 +58,10 @@ def test_pyright_baseline():
5558
),
5659
PyrightDiagnostic(
5760
severity="information",
58-
message='Type of "DefineConverter.__init__" is '
59-
'"(self: DefineConverter, with_converter: int) -> None"',
61+
message='Type of "DefineConverter.__init__" is "(self: '
62+
"DefineConverter, with_converter: str | bytes | bytearray | "
63+
"memoryview | array[Any] | mmap | _CData | PickleBuffer | "
64+
'SupportsInt | SupportsIndex | SupportsTrunc) -> None"',
6065
),
6166
PyrightDiagnostic(
6267
severity="error",

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ deps = nodeenv
6969
commands =
7070
nodeenv --prebuilt --node=lts --force {envdir}
7171
npm install -g --no-package-lock --no-save pyright
72+
pyright --version
7273
pytest tests/test_pyright.py -vv
7374

7475

0 commit comments

Comments
 (0)