Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tjkuson opened this issue Oct 31, 2023 · 4 comments · Fixed by #16381
Closed

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

tjkuson opened this issue Oct 31, 2023 · 4 comments · Fixed by #16381
Labels
crash topic-pep-646 PEP 646 (TypeVarTuple, Unpack)

Comments

@tjkuson
Copy link

tjkuson commented Oct 31, 2023

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
@ilevkivskyi
Copy link
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.

@ilevkivskyi ilevkivskyi added topic-pep-646 PEP 646 (TypeVarTuple, Unpack) and removed topic-typed-dict labels Oct 31, 2023
@tjkuson tjkuson changed the title Crash when passing name annotated as nested Unpack to f-string Crash involving tuple[Unpack[tuple]] annotation Oct 31, 2023
@tjkuson
Copy link
Author

tjkuson commented Oct 31, 2023

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.

@hauntsaninja
Copy link
Collaborator

Is the codebase you ran into this on open source?

@tjkuson
Copy link
Author

tjkuson commented Nov 1, 2023

Is the codebase you ran into this on open source?

No, sorry.

ilevkivskyi added a commit that referenced this issue Nov 1, 2023
Fixes #16380

Fix is quite straightforward, what was an `assert` really needs to be an
`if`.

---------

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
JukkaL pushed a commit that referenced this issue Nov 1, 2023
Fixes #16380

Fix is quite straightforward, what was an `assert` really needs to be an
`if`.

---------

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash topic-pep-646 PEP 646 (TypeVarTuple, Unpack)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants