Fix pyright for 1.1.311 (#1138)

They support converters now!
This commit is contained in:
Hynek Schlawack 2023-06-03 12:12:03 +02:00 committed by GitHub
parent a6778cf7aa
commit 2b3a427147
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 9 deletions

View File

@ -89,9 +89,6 @@ class SomeClass:
:::{warning}
The *Pyright* inferred types are a tiny subset of those supported by *Mypy*, including:
- The generated `__init__` signature only includes the attribute type annotations.
It currently does not include attribute `converter` types.
- The `attrs.frozen` decorator is not typed with frozen attributes, which are properly typed via `attrs.define(frozen=True)`.
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).

View File

@ -21,6 +21,8 @@ class DefineConverter:
reveal_type(DefineConverter.__init__) # noqa
DefineConverter(with_converter=b"42")
@attr.frozen()
class Frozen:

View File

@ -1,10 +1,13 @@
# SPDX-License-Identifier: MIT
from __future__ import annotations
import json
import os.path
import shutil
import subprocess
from pathlib import Path
import pytest
import attrs
@ -23,7 +26,7 @@ class PyrightDiagnostic:
message: str
def parse_pyright_output(test_file):
def parse_pyright_output(test_file: Path) -> set[PyrightDiagnostic]:
pyright = subprocess.run(
["pyright", "--outputjson", str(test_file)], capture_output=True
)
@ -42,11 +45,11 @@ def test_pyright_baseline():
decorated class types.
"""
test_file = os.path.dirname(__file__) + "/dataclass_transform_example.py"
test_file = Path(__file__).parent / "dataclass_transform_example.py"
diagnostics = parse_pyright_output(test_file)
# Expected diagnostics as per pyright 1.1.135
# Expected diagnostics as per pyright 1.1.311
expected_diagnostics = {
PyrightDiagnostic(
severity="information",
@ -55,8 +58,10 @@ def test_pyright_baseline():
),
PyrightDiagnostic(
severity="information",
message='Type of "DefineConverter.__init__" is '
'"(self: DefineConverter, with_converter: int) -> None"',
message='Type of "DefineConverter.__init__" is "(self: '
"DefineConverter, with_converter: str | bytes | bytearray | "
"memoryview | array[Any] | mmap | _CData | PickleBuffer | "
'SupportsInt | SupportsIndex | SupportsTrunc) -> None"',
),
PyrightDiagnostic(
severity="error",

View File

@ -69,6 +69,7 @@ deps = nodeenv
commands =
nodeenv --prebuilt --node=lts --force {envdir}
npm install -g --no-package-lock --no-save pyright
pyright --version
pytest tests/test_pyright.py -vv