Skip to content

Incorrect warning related to mutable defaults for pydantic #1031

@hozn

Description

@hozn

Describe the bug

This feels related to #340, but after upgrading to v0.4.16, I'm getting errors in Pycharm related to having mutable default values. This is perfectly fine to do in Pydantic: https://docs.pydantic.dev/latest/concepts/fields/#mutable-default-values

To Reproduce
Steps to reproduce the behavior:

  1. Create a basic pydantic class that has a mutable default:
from typing import Any
from pydantic import BaseModel, Field

class MyModel(BaseModel):
    my_attr: dict[str, Any] = {
        "x": 1
    }

Hover over; Pycharm shows as error:
image

Expected behavior
This should not be an error. Or really even a warning.

Environments (please complete the following information):

  • IDE: PyCharm 2024.3.1
  • OS: MacOS 14.2.1
  • Pydantic Version 2.10.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