Skip to content

Crash involving tuple[Unpack[tuple]] annotation #16380

Closed

Description

@tjkuson

Crash Report

Ran the mypy development branch on a codebase and it crashed. I managed to reduce the crash to a function parameter typed as a nested Unpack that was passed to an f-string.

The reason I was using the development branch of mypy was that it contained a bug fix not yet in the latest release. Downgrading to 1.6.1 causes the crash to stop happening unless you pass --enable-incomplete-feature=Unpack.

The closest issue I found was #16285 which seems to be closed as completed, but I am still able to produce this crash on the latest development branch which includes the commit that closed the issue.

Traceback

/tmp/hmm.py:5: 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.6.1
Traceback (most recent call last):
  File "mypy/checkexpr.py", line 5366, in accept
  File "mypy/checkexpr.py", line 452, in visit_call_expr
  File "mypy/checkexpr.py", line 581, in visit_call_expr_inner
  File "mypy/checkexpr.py", line 1420, in check_call_expr_with_callee_type
  File "mypy/checkexpr.py", line 1514, in check_call
  File "mypy/checkexpr.py", line 1715, in check_callable_call
  File "mypy/checkexpr.py", line 2408, in check_argument_types
AssertionError:
/tmp/hmm.py:5: : note: use --pdb to drop into pdb

To Reproduce

from typing import Unpack


def foo(*keys: Unpack[tuple[Unpack[tuple]]]):
    return f"{keys}"

Your Environment

  • Mypy version used: 1.6.1
  • Mypy command-line flags: --enable-incomplete-feature=Unpack
  • Python version used: 3.11.6
  • Operating system and version: macOS 14.1

Activity

  1. ilevkivskyi commented on Oct 31, 2023

    @ilevkivskyi
    Member

    A more minimal example:

    from typing import Unpack
    
    def test(*x: object): ...
    
    keys: tuple[Unpack[tuple]]
    test(keys, 1)

    And this is actually a counter-example to the code I never fully understood. I will submit a fix either later today or tomorrow morning.

  2. changed the title [-]Crash when passing name annotated as nested `Unpack` to f-string[/-] [+]Crash involving `tuple[Unpack[tuple]]` annotation[/+] on Oct 31, 2023
  3. tjkuson commented on Oct 31, 2023

    @tjkuson
    Author

    Thanks! I have changed the title to better reflect the crash. I wrongly thought the f-strings were involved, as changing the f-string to, e.g., a print call in the example made the crash stop.

  4. hauntsaninja commented on Nov 1, 2023

    @hauntsaninja
    Collaborator

    Is the codebase you ran into this on open source?

  5. tjkuson commented on Nov 1, 2023

    @tjkuson
    Author

    Is the codebase you ran into this on open source?

    No, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions