Skip to content

Version 0.19.1 breaks default_factory that returns empty list #1353

@tiangolo

Description

@tiangolo

Fixed in #1350, adding the issue for future reference.

Discussed in #1349

Originally posted by KiSchnelle September 22, 2025

First Check

  • I added a very descriptive title here.
  • I used the GitHub search to find a similar question and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorials in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from dataclasses import dataclass
from typing import Annotated

import typer

app = typer.Typer()


def default_classes() -> list[str]:
    return []


@app.command()
@dataclass
class TestCommandd:
    classes: Annotated[
        list[str],
        typer.Option(
            default_factory=default_classes,
            help="List of classes.",
            rich_help_panel="Options",
            show_default=False,
        ),
    ]

    def __post_init__(self) -> None:
        print(self.classes)


if __name__ == "__main__":
    app()

Description

Hi,

I found a for me quite breaking change, probably cause I use it a bit unconventional:D
Probably this pull was the reason.
#1018

In typer version 0.19.0 this returns [] as wanted. In version 0.19.1 this returns the function instead.
I know it's probably not the best way to use like this but I would say it's kind of a breaking change. Anyway if the new way is wanted it should be documented in release notes maybe.

cheers
Kilian

Operating System

Linux

Operating System Details

No response

Typer Version

0.19.0 and 0.19.1

Python Version

3.13.5

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions