Skip to content

In TypeVar, using * and Unpack for default argument gets error while they work properly for *constraints and bound argument #20451

@hyperkai

Description

@hyperkai

*Memo:

  • mypy test.py
  • mypy --show-traceback test.py
  • mypy 1.19.1
  • Python 3.14.0
  • Windows 11

In TypeVar, using * and Unpack for default argument gets the error while they work properly for *constraints and bound argument as shown below:

<default argument>:

from typing import TypeVar, Unpack
                                    # ↓
T1 = TypeVar('T1', default=tuple[int, *tuple[str, None]])        # Error
T2 = TypeVar('T2', default=tuple[int, Unpack[tuple[str, None]]]) # Error
                                    # ↑↑↑↑↑↑

<*constraints argument>:

from typing import TypeVar, Unpack
                            # ↓                            # ↓
T1 = TypeVar('T1', tuple[int, *tuple[str, None]], tuple[int, *tuple[str, None]])               # No error
T2 = TypeVar('T2', tuple[int, Unpack[tuple[str, None]]], tuple[int, Unpack[tuple[str, None]]]) # No error
                            # ↑↑↑↑↑↑                              # ↑↑↑↑↑↑

<bound argument>:

from typing import TypeVar, Unpack
                                  # ↓
T1 = TypeVar('T1', bound=tuple[int, *tuple[str, None]])        # No error
T2 = TypeVar('T2', bound=tuple[int, Unpack[tuple[str, None]]]) # No error
                                  # ↑↑↑↑↑↑

error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.19.1
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "mypy\checkexpr.py", line 6105, in accept
File "mypy\nodes.py", line 2954, in accept
File "mypy\checkexpr.py", line 6319, in visit_type_var_expr
File "mypy\subtypes.py", line 190, in is_subtype
File "mypy\subtypes.py", line 359, in _is_subtype
File "mypy\types.py", line 2835, in accept
File "mypy\subtypes.py", line 794, in visit_tuple_type
File "mypy\typeops.py", line 117, in tuple_fallback
NotImplementedError:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions