Incorrect stub generation for subclasses of `pydantic.BaseModel`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the shown example.py and stubgen -m example, then trace the stubgen path that handles annotated class-body defaults for subclasses of pydantic.BaseModel. Done means the generated example.pyi contains ... for both defaults, with regression coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100