Skip to content

Pydantic Dataclasses kw-only field: Insert required arguments #1051

@aneroid

Description

@aneroid

Describe the bug

If a field in a Pydantic dataclass has a kw_only=True param, then PyCharm shows a hint/underline without a message, and the Alt+Enter actions popup says "Insert required arguments".

However, this does not happen for a class which inherits Pydantic's BaseModel.

Further, the underline exists but there's no warning in the 'Problems' tab. Only shows up when pressing Alt+Enter (on Windows).

Note: When I disable the plugin, the issue stops. That incorrect warning highlight and pop-up don't appear.

To Reproduce
Steps to reproduce the behavior:

  1. Using this example code
from pydantic.dataclasses import dataclass as pyd_dataclass
from pydantic import Field, BaseModel

@pyd_dataclass
class MoreParams:
    value: str | None = Field(None, kw_only=True)

smp = MoreParams(value="val")  # warning underline here

class OkayParams(BaseModel):
    value: str | None = Field(None, kw_only=True)

okp = OkayParams(value="val")  # this is okay
  1. There will be a dark-orange/red underline near the ) at the end of smp = MoreParams(value="val")
  2. Mouse-over it (nothing happens)
  3. Press Alt+Enter (windows) and we get a pop up/hint for "Insert required arguments"

Expected behavior

  1. Should not be an inspection error.
  2. And inspection errors should also show up in the 'Problems' tab, whether they are correct or not.

Screenshots

Image
Image
Image

Environments:

  • IDE: PyCharm 2024.3.5 (Professional Edition)
  • OS: Windows10
  • Pydantic Version 2.11.3
  • Plugin version 0.4.16

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions