Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converter type in attrs not correctly passed on to __init__ #7713

Closed
pvandyken opened this issue Apr 16, 2024 · 2 comments
Closed

converter type in attrs not correctly passed on to __init__ #7713

pvandyken opened this issue Apr 16, 2024 · 2 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working regression

Comments

@pvandyken
Copy link

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.

@pvandyken pvandyken added the bug Something isn't working label Apr 16, 2024
@erictraut erictraut changed the title converter type in attrs not correctly passed on to __init__ Regression: converter type in attrs not correctly passed on to __init__ Apr 24, 2024
@erictraut erictraut changed the title Regression: converter type in attrs not correctly passed on to __init__ converter type in attrs not correctly passed on to __init__ May 15, 2024
erictraut added a commit that referenced this issue May 18, 2024
…es when the converter refers to a generic class constructor. This addresses #7713.
@erictraut
Copy link
Collaborator

I've fixed the regression, but it's important to note that support for "converter" is experimental and is contingent on the acceptance of PEP 712. The steering council recently signaled that they are disinclined to accept this PEP, although they haven't issued their final decision. I've disabled this functionality by default because I don't want pyright users to assume that it will be implemented. It is still available if you specify "enableExperimentalFeatures: true" in your pyright configuration file. This reflects the fact that the functionality is experimental and will be removed in the future if the steering council rejects PEP 712.

@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label May 18, 2024
@erictraut
Copy link
Collaborator

This is addressed in pyright 1.1.364.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working regression
Projects
None yet
Development

No branches or pull requests

2 participants