koxudaxi / pydantic-pycharm-plugin

PyCharm plugin for pydantic. This plugin provides autocompletion, inspection, type-checking, inserting unfilled argument, and more.
https://koxudaxi.github.io/pydantic-pycharm-plugin/
MIT License
437 stars 14 forks source link

`@pydantic.dataclasses.dataclass` not working as `@dataclasses.dataclass` #920

Open trim21 opened 2 months ago

trim21 commented 2 months ago

Describe the bug A clear and concise description of what the bug is.

@pydantic.dataclasses.dataclass's __init__ type hint stop working

To Reproduce Steps to reproduce the behavior:

  1. install ide, plugin and pydantic
  2. copy file content
  3. try auto-complete
  4. and it's not woking

Expected behavior A clear and concise description of what you expected to happen. should work as stdlib dataclasses image

Screenshots If applicable, add screenshots to help explain your problem. Also, gif movies are recommended.

Environments (please complete the following information):

Additional context Add any other context about the problem here.

import enum

import pydantic.dataclasses

@enum.verify(enum.UNIQUE)
class SeedingStrategy(enum.Enum):
    Rolling = "rolling"
    Reserve = "reserve"

@enum.verify(enum.UNIQUE)
class Website(enum.StrEnum):
    a = "a"
    b = "b"

    def category(self):
        if self in [e for e in Website]:
            return self

        raise Exception("missing category config")

@pydantic.dataclasses.dataclass
class Config:
    site: Website
    cluster: str

    strategy: SeedingStrategy

    qb_category: str

    qb_max_queue: int = 5
    qb_tags: list = pydantic.Field([])

    sample_rate: float = pydantic.Field(default=1, gt=0, le=1)

if __name__ == "__main__":
    Config(sa|) # <- cursor here

image

trim21 commented 2 months ago

emmmm, this can be fixed by changing import pydantic to from pydantic import dataclasses and replace @pydantic.dataclasses.dataclass with @dataclasses.dataclass