Version 0.19.1 breaks default_factory that returns empty list #1349
-
        First Check
 Commit to Help
 Example Codefrom 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()DescriptionHi, I found a for me quite breaking change, probably cause I use it a bit unconventional:D In typer version 0.19.0 this returns [] as wanted. In version 0.19.1 this returns the function instead. cheers Operating SystemLinux Operating System DetailsNo response Typer Version0.19.0 and 0.19.1 Python Version3.13.5 Additional ContextNo response  | 
  
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
| 
         The same without  from typing import Annotated
import typer
app = typer.Typer()
def default_classes() -> list[str]:
    return []
@app.command()
def cmd(
    classes: Annotated[
        list[str],
        typer.Option(
            default_factory=default_classes,
        ),
    ]
):
    print(classes)  # <function default_classes at 0x736d4dfba340>
if __name__ == "__main__":
    app() | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         Thanks for the report! You're right that this broke accidentally in PR #1018 - I'll be looking into it.  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         PR with some additional background & analysis, and a fix for this regression: #1350  | 
  
Beta Was this translation helpful? Give feedback.
PR with some additional background & analysis, and a fix for this regression: #1350