Skip to content

pydantic - protected attributes are incorrectly treated as fields #3544

@DetachHead

Description

@DetachHead

Describe the Bug

from pydantic import BaseModel


class Foo(BaseModel):
    a: int
    _a: int

    def initialize(self):
        self._a = 1


foo = Foo(a=1) # error: Missing argument `_a` in function `Foo.__init__` [missing-argument]

in pydantic, an attribute prefixed with _ is not considered a field. this code works at runtime

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    pydanticIssues related to support for Pydantic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions