Skip to content

PR #349 breaks typer compatibility: RuntimeError with 'bool | None' type hints #355

@christian-byrne

Description

@christian-byrne

Description

PR #349 ("Set minimal supported python to version 3.10", commit f5d6790) changed type hints from Optional[bool] to bool | None syntax throughout the codebase. However, this breaks compatibility with typer versions older than 0.12.4.

The current pyproject.toml specifies typer>=0.9, which allows installation of typer versions that do not support PEP 604 union syntax (X | None) in function parameters decorated with typer.Option().

Error

This is causing CI failures in ComfyUI: https://github.com/Comfy-Org/ComfyUI/actions/runs/21105052317/job/60695001519

RuntimeError: Type not yet supported: bool | None

Full traceback:

╭───────────────────── Traceback (most recent call last) ──────────────────────╮
│ /home/robin.j.huang/miniconda3/envs/gha-comfyui-3.11-nightly/bin/comfy:8 in  │
│ <module>                                                                     │
│                                                                              │
│ ❱ 8 │   sys.exit(main())                                                     │
│                                                                              │
│ /home/robin.j.huang/miniconda3/envs/gha-comfyui-3.11-nightly/lib/python3.11/ │
│ site-packages/comfy_cli/cmdline.py:35 in main                                │
│                                                                              │
│ ❱  35 │   app()                                                              │
│                                                                              │
│ /home/.../typer/main.py:788 in get_click_type                                │
╰──────────────────────────────────────────────────────────────────────────────╯
RuntimeError: Type not yet supported: bool | None

Affected Files

  • comfy_cli/cmdline.py: entry() function (recent, here params), install() function (nvidia, amd, m_series, intel_arc, cpu params)
  • comfy_cli/command/custom_nodes/command.py: restore_snapshot() function (pip_non_url, pip_non_local_url, pip_local_url params)

Root Cause

Typer did not support PEP 604 union syntax (bool | None) until PR fastapi/typer#548 was merged on Aug 17, 2024 and released in typer 0.12.4.

Suggested Fix

Either:

  1. Update typer dependency (recommended):

    -  "typer>=0.9",
    +  "typer>=0.12.4",
  2. Revert to Optional[bool] syntax for typer-decorated parameters only:

    # Instead of:
    nvidia: bool | None = typer.Option(...)
    
    # Use:
    nvidia: Optional[bool] = typer.Option(...)

Option 1 is cleaner and aligns with the Python 3.10+ modernization goal of PR #349.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dependenciesPull requests that update a dependency file

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions