Skip to content

Python 3.14 compatibility: magics.py uses type annotation in argparse argument #5639

@skorfmann

Description

@skorfmann

Description

SQLMesh fails to start on Python 3.14 due to a type annotation being passed to argparse's type parameter in sqlmesh/magics.py.

Error

File ".../sqlmesh/magics.py", line 629, in SQLMeshMagics
    @magic_arguments()
File ".../IPython/core/magic_arguments.py", line 243, in __call__
    func.parser = construct_parser(func)
File ".../argparse.py", line 1548, in add_argument
    raise TypeError(f'{type_func!r} is not callable')
TypeError: bool | typing.Iterable[str] is not callable

Root Cause

In sqlmesh/magics.py around line 635:

@argument(
    "--expand",
    type=t.Union[bool, t.Iterable[str]],  # <-- type annotation, not a callable
    help="...",
)

argparse's type parameter expects a callable function to convert string arguments, not a type annotation. Python 3.14 enforces this more strictly.

Environment

  • Python: 3.14.2
  • SQLMesh: 0.228.1
  • IPython: 9.8.0
  • OS: macOS

Suggested Fix

Either:

  1. Remove the type parameter (let it be a string)
  2. Use a proper converter function
  3. Use nargs and handle the type conversion in the magic function itself
# Option 1: Remove type, handle in function
@argument("--expand", help="...")

# Option 2: Use a converter function  
def parse_expand(value):
    if value.lower() in ('true', 'false'):
        return value.lower() == 'true'
    return value.split(',')

@argument("--expand", type=parse_expand, help="...")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions