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 with functools.partial and Unpack #17405

Closed
cdce8p opened this issue Jun 19, 2024 · 0 comments · Fixed by #17423
Closed

Crash with functools.partial and Unpack #17405

cdce8p opened this issue Jun 19, 2024 · 0 comments · Fixed by #17423
Labels
crash topic-plugins The plugin API and ideas for new plugins

Comments

@cdce8p
Copy link
Collaborator

cdce8p commented Jun 19, 2024

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]
@cdce8p cdce8p added crash topic-plugins The plugin API and ideas for new plugins topic-pep-646 PEP 646 (TypeVarTuple, Unpack) and removed topic-pep-646 PEP 646 (TypeVarTuple, Unpack) labels Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash topic-plugins The plugin API and ideas for new plugins
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant