pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Support dataclasses

Open NChechulin opened this issue 2 years ago • 2 comments

Python and pydantic dataclasses support would be great, since at the moment (at least in strict mode) pylance complains about use of named parameters in dataclass __init__ functions:

@dataclass
class MyClass:
    a: str
    b: str


MyClass(a="Hello", b="World!")
        ^^^^^^^^^^^^^^^^^^^^^
Error: Expected 0 positional argumentsPylance[reportGeneralTypeIssues](https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules)

I understand that __init__ is generated in runtime, however, I think dataclasses are used often enough, so we could try to come up with some kind of workaround.

NChechulin avatar Aug 21 '22 14:08 NChechulin

Pyright (the static type checker that underlies pylance) already provides support for stdlib dataclasses. It also supports most functionality for pydantic dataclasses. If you are using pydantic, please verify that you have an up-to-date version installed, as older versions of pydantic will not work. I suspect that's why you're seeing the problem you're reporting here.

erictraut avatar Aug 21 '22 14:08 erictraut

I had this issue before when the python extensions became deprecated and moved to official Microsoft. Currently I face no such issue with dataclasses.

thethiny avatar Aug 25 '22 08:08 thethiny

Closing old issue. Presuming updating Pydantic worked. If this is still a problem, please reopen with the information requested. thanks

judej avatar Oct 17 '22 19:10 judej