diff --git a/docs/types.md b/docs/types.md index 6ef3e669..470a8c33 100644 --- a/docs/types.md +++ b/docs/types.md @@ -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). diff --git a/tests/dataclass_transform_example.py b/tests/dataclass_transform_example.py index aa0797dd..23505d90 100644 --- a/tests/dataclass_transform_example.py +++ b/tests/dataclass_transform_example.py @@ -21,6 +21,8 @@ class DefineConverter: reveal_type(DefineConverter.__init__) # noqa +DefineConverter(with_converter=b"42") + @attr.frozen() class Frozen: diff --git a/tests/test_pyright.py b/tests/test_pyright.py index cc5fe8dd..7a1d72e3 100644 --- a/tests/test_pyright.py +++ b/tests/test_pyright.py @@ -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", diff --git a/tox.ini b/tox.ini index faf916da..867490cb 100644 --- a/tox.ini +++ b/tox.ini @@ -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