Skip to content

Crash with functools.partial and Unpack #17405

Closed

Description

@cdce8p

Crash Report
Crash first introduced with the new plugin for functools.partial in #16939.
/CC @hauntsaninja

Traceback

$ mypy test.py --show-traceback
test.py:11: 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.11.0+dev.10f18a82b612b6127659cd64aa60c10b9cc7a904
Traceback (most recent call last):
  ...
  File ".../mypy/plugins/functools.py", line 247, in partial_call_callback
    result = ctx.api.expr_checker.check_call(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../mypy/checkexpr.py", line 1554, in check_call
    return self.check_callable_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../mypy/checkexpr.py", line 1643, in check_callable_call
    callee = callee.with_unpacked_kwargs().with_normalized_var_args()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../mypy/types.py", line 2087, in with_unpacked_kwargs
    assert isinstance(last_type, TypedDictType)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError:

To Reproduce

from typing import TypedDict, Unpack
from functools import partial

class Data(TypedDict, total=False):
    a1: int

def f(**kwargs: Unpack[Data]) -> None:
    ...

def g(**kwargs: Unpack[Data]) -> None:
    partial(f, **kwargs)()

Your Environment

  • Mypy version used: 1.11.0+dev.10f18a82b612b6127659cd64aa60c10b9cc7a904 (current master)
  • Python version used: 3.12

--
Changing the example slightly to add a second variable to Data results in new errors but the crash goes away.

from typing import TypedDict, Unpack
from functools import partial

class Data(TypedDict, total=False):
    a1: int
    a2: int  # <-- new

def f(**kwargs: Unpack[Data]) -> None:
    ...

def g(**kwargs: Unpack[Data]) -> None:
    partial(f, **kwargs)()
test.py:12: error: "f" gets multiple values for keyword argument "a1"  [misc]
test.py:12: error: "f" gets multiple values for keyword argument "a2"  [misc]

Activity

  1. added
    topic-plugins
    topic-pep-646
    and removed
    topic-pep-646
    on Jun 19, 2024
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

    crashtopic-plugins

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions