Skip to content

Incorrect stub generation for subclasses of pydantic.BaseModel #16968

Open
@jborman-stonex

Description

@jborman-stonex

Bug Report

stubgen does not properly generate ellipses for default values set in the scope of the class body of a Pydantic model.

To Reproduce

Running stubgen -m example

# example.py
from pydantic import BaseModel


class Foo(BaseModel):
    abc: int = 1
    xyz: str = "abc"

Should produce

Expected Behavior

# example.pyi
from pydantic import BaseModel

class Foo(BaseModel):
    abc: int = ...
    xyz: str = ...

stubgen should be populating the default annotation with ellipses, instead they are missing.

Actual Behavior

# example.pyi
from pydantic import BaseModel

class Foo(BaseModel):
    abc: int
    xyz: str

Your Environment

  • Mypy version used: mypy 1.8.0 (compiled: yes)
  • Mypy command-line flags: stubgen -m example
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.11.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions