Unpin/fix Pyright (#1302)
* Unpin/fix Pyright Fixes #1278 * Consistency * Remove stale comment * Add explanation why we need experimental features
This commit is contained in:
parent
6f64cd6d19
commit
6e25a0c4f5
|
@ -272,3 +272,8 @@ showcontent = true
|
||||||
pretty = true
|
pretty = true
|
||||||
disallow_untyped_defs = true
|
disallow_untyped_defs = true
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
|
|
||||||
|
|
||||||
|
[tool.pyright]
|
||||||
|
# We need epexrimental features for converters.
|
||||||
|
enableExperimentalFeatures = true
|
||||||
|
|
|
@ -15,7 +15,6 @@ reveal_type(Define.__init__) # noqa: F821
|
||||||
|
|
||||||
@attr.define()
|
@attr.define()
|
||||||
class DefineConverter:
|
class DefineConverter:
|
||||||
# mypy plugin adapts the "int" method signature, pyright does not
|
|
||||||
with_converter: int = attr.field(converter=int)
|
with_converter: int = attr.field(converter=int)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,6 @@ from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import attrs
|
|
||||||
|
|
||||||
|
|
||||||
pytestmark = [
|
pytestmark = [
|
||||||
pytest.mark.skipif(
|
pytest.mark.skipif(
|
||||||
|
@ -20,21 +18,16 @@ pytestmark = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@attrs.frozen
|
def parse_pyright_output(test_file: Path) -> set[tuple[str, str]]:
|
||||||
class PyrightDiagnostic:
|
|
||||||
severity: str
|
|
||||||
message: str
|
|
||||||
|
|
||||||
|
|
||||||
def parse_pyright_output(test_file: Path) -> set[PyrightDiagnostic]:
|
|
||||||
pyright = subprocess.run( # noqa: PLW1510
|
pyright = subprocess.run( # noqa: PLW1510
|
||||||
["pyright", "--outputjson", str(test_file)], capture_output=True
|
["pyright", "--outputjson", str(test_file)], capture_output=True
|
||||||
)
|
)
|
||||||
|
|
||||||
pyright_result = json.loads(pyright.stdout)
|
pyright_result = json.loads(pyright.stdout)
|
||||||
|
|
||||||
|
# We use tuples instead of proper classes to get nicer diffs from pytest.
|
||||||
return {
|
return {
|
||||||
PyrightDiagnostic(d["severity"], d["message"])
|
(d["severity"], d["message"])
|
||||||
for d in pyright_result["generalDiagnostics"]
|
for d in pyright_result["generalDiagnostics"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,41 +42,40 @@ def test_pyright_baseline():
|
||||||
|
|
||||||
diagnostics = parse_pyright_output(test_file)
|
diagnostics = parse_pyright_output(test_file)
|
||||||
|
|
||||||
# Expected diagnostics as per pyright 1.1.311
|
|
||||||
expected_diagnostics = {
|
expected_diagnostics = {
|
||||||
PyrightDiagnostic(
|
(
|
||||||
severity="information",
|
"information",
|
||||||
message='Type of "Define.__init__" is'
|
'Type of "Define.__init__" is "(self: Define, a: str, b: int) -> None"',
|
||||||
' "(self: Define, a: str, b: int) -> None"',
|
|
||||||
),
|
),
|
||||||
PyrightDiagnostic(
|
(
|
||||||
severity="information",
|
"information",
|
||||||
message='Type of "DefineConverter.__init__" is '
|
'Type of "DefineConverter.__init__" is '
|
||||||
'"(self: DefineConverter, with_converter: str | Buffer | '
|
'"(self: DefineConverter, with_converter: str | Buffer | '
|
||||||
'SupportsInt | SupportsIndex | SupportsTrunc) -> None"',
|
'SupportsInt | SupportsIndex | SupportsTrunc) -> None"',
|
||||||
),
|
),
|
||||||
PyrightDiagnostic(
|
(
|
||||||
severity="error",
|
"error",
|
||||||
message='Cannot assign member "a" for type '
|
'Cannot assign to attribute "a" for class '
|
||||||
'"Frozen"\n\xa0\xa0"Frozen" is frozen\n\xa0\xa0\xa0\xa0Member "__set__" is unknown',
|
'"Frozen"\n\xa0\xa0"Frozen" is frozen\n\xa0\xa0\xa0\xa0'
|
||||||
|
'Attribute "__set__" is unknown',
|
||||||
),
|
),
|
||||||
PyrightDiagnostic(
|
(
|
||||||
severity="information",
|
"information",
|
||||||
message='Type of "d.a" is "Literal[\'new\']"',
|
'Type of "d.a" is "Literal[\'new\']"',
|
||||||
),
|
),
|
||||||
PyrightDiagnostic(
|
(
|
||||||
severity="error",
|
"error",
|
||||||
message='Cannot assign member "a" for type '
|
'Cannot assign to attribute "a" for class '
|
||||||
'"FrozenDefine"\n\xa0\xa0"FrozenDefine" is frozen\n\xa0\xa0\xa0\xa0'
|
'"FrozenDefine"\n\xa0\xa0"FrozenDefine" is frozen\n\xa0\xa0\xa0\xa0'
|
||||||
'Member "__set__" is unknown',
|
'Attribute "__set__" is unknown',
|
||||||
),
|
),
|
||||||
PyrightDiagnostic(
|
(
|
||||||
severity="information",
|
"information",
|
||||||
message='Type of "d2.a" is "Literal[\'new\']"',
|
'Type of "d2.a" is "Literal[\'new\']"',
|
||||||
),
|
),
|
||||||
PyrightDiagnostic(
|
(
|
||||||
severity="information",
|
"information",
|
||||||
message='Type of "af.__init__" is "(_a: int) -> None"',
|
'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)
|
diagnostics = parse_pyright_output(test_pyright_attrsinstance_compat_path)
|
||||||
expected_diagnostics = {
|
expected_diagnostics = {
|
||||||
PyrightDiagnostic(
|
(
|
||||||
severity="information",
|
"information",
|
||||||
message='Type of "attrs.AttrsInstance" is "type[AttrsInstance]"',
|
'Type of "attrs.AttrsInstance" is "type[AttrsInstance]"',
|
||||||
),
|
)
|
||||||
}
|
}
|
||||||
assert diagnostics == expected_diagnostics
|
assert diagnostics == expected_diagnostics
|
||||||
|
|
Loading…
Reference in New Issue