pyright
pyright copied to clipboard
`converter` type in attrs not correctly passed on to `__init__`
Describe the bug
In pyright 1.1.358, the generated __init__
types for attrs-wrapped classes no longer respect functions or constructors provided to the converter
argument of attrs.field
. The now-expected type seems to vary depending on the converter, I haven't found an exact pattern. Simple converters like str
seem to work fine.
Code or Screenshots
# test.py
from __future__ import annotations
import attrs
@attrs.define
class A:
a: dict[str, str] = attrs.field(converter=dict)
test = A(a={"foo": "bar"})
$ pyright test.py
.../test.py
.../test.py:10:12 - error: Argument of type "dict[str, str]" cannot be assigned to parameter "a" of type "Iterable[list[str]] | Iterable[list[bytes]]" in function "__init__"
Type "dict[str, str]" cannot be assigned to type "Iterable[list[str]] | Iterable[list[bytes]]"
"dict[str, str]" is incompatible with "Iterable[list[str]]"
Type parameter "_T_co@Iterable" is covariant, but "str" is not a subtype of "list[str]"
"str" is incompatible with "list[str]"
"dict[str, str]" is incompatible with "Iterable[list[bytes]]"
Type parameter "_T_co@Iterable" is covariant, but "str" is not a subtype of "list[bytes]"
"str" is incompatible with "list[bytes]" (reportArgumentType)
1 error, 0 warnings, 0 informations
VS Code extension or command-line Just the command-line, this version is not yet shipped with pylance.