Skip to content

mypyc crashes when working on ParamSpec.kwargs #18784

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

Closed
kasium opened this issue Mar 11, 2025 · 1 comment · Fixed by #18789
Closed

mypyc crashes when working on ParamSpec.kwargs #18784

kasium opened this issue Mar 11, 2025 · 1 comment · Fixed by #18789
Labels
crash topic-mypyc mypyc bugs topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@kasium
Copy link

kasium commented Mar 11, 2025

Bug Report

When using mypyc on code using ParamSpec.kwargs, a crash occurs

To Reproduce

from __future__ import annotations

from typing import Any, Callable, ParamSpec, TypeVar

PARAM = ParamSpec("PARAM")
RET = TypeVar("RET")


def decorator() -> Callable[[Callable[PARAM, RET]], Callable[PARAM, RET]]:
    def _wrapper(function: Callable[PARAM, RET]) -> Callable[PARAM, RET]:
        def _inner(*args: PARAM.args, **kwargs: PARAM.kwargs) -> Any:
            data = {key: arg for key, arg in kwargs.items()}
            function(*args, **kwargs)

        return _inner

    return _wrapper

Expected Behavior

no crash

Actual Behavior

Traceback (most recent call last):
foo.py:13: AssertionError: PARAM.kwargs`-1

Your Environment

  • Mypy version used: mypy 1.15.0 (compiled: yes)
  • Mypy command-line flags: n/a
  • Mypy configuration options from mypy.ini (and other config files): n/a
  • Python version used: 3.13.0
@kasium kasium added the bug mypy got something wrong label Mar 11, 2025
@sterliakov sterliakov added crash topic-paramspec PEP 612, ParamSpec, Concatenate topic-mypyc mypyc bugs and removed bug mypy got something wrong labels Mar 11, 2025
@sterliakov
Copy link
Collaborator

sterliakov commented Mar 11, 2025

Traceback from current master (a.py:12 is the data = ... line - dictcomp):

$ mypyc a.py
Traceback (most recent call last):
  File "/tmp/tmp.R3k7W0wi65/build/setup.py", line 5, in <module>
    ext_modules=mypycify(['a.py'], opt_level="3", debug_level="1", strict_dunder_typing=False),
  File "/home/stas/Documents/Work/mypy/mypyc/build.py", line 531, in mypycify
    groups, group_cfilenames = mypyc_build(
  File "/home/stas/Documents/Work/mypy/mypyc/build.py", line 436, in mypyc_build
    group_cfiles, ops_text = generate_c(
  File "/home/stas/Documents/Work/mypy/mypyc/build.py", line 244, in generate_c
    modules, ctext = emitmodule.compile_modules_to_c(
  File "/home/stas/Documents/Work/mypy/mypyc/codegen/emitmodule.py", line 428, in compile_modules_to_c
    modules = compile_modules_to_ir(result, mapper, compiler_options, errors)
  File "/home/stas/Documents/Work/mypy/mypyc/codegen/emitmodule.py", line 272, in compile_modules_to_ir
    scc_ir = compile_scc_to_ir(trees, result, mapper, compiler_options, errors)
  File "/home/stas/Documents/Work/mypy/mypyc/codegen/emitmodule.py", line 227, in compile_scc_to_ir
    modules = build_ir(scc, result.graph, result.types, mapper, compiler_options, errors)
  File "/home/stas/.local/share/uv/python/cpython-3.13.0-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 85, in inner
    return func(*args, **kwds)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/main.py", line 95, in build_ir
    transform_mypy_file(builder, module)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/main.py", line 141, in transform_mypy_file
    builder.accept(node)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/builder.py", line 290, in accept
    node.accept(self.visitor)
  File "/home/stas/Documents/Work/mypy/mypy/nodes.py", line 813, in accept
    return visitor.visit_func_def(self)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/visitor.py", line 181, in visit_func_def
    transform_func_def(self.builder, fdef)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/function.py", line 101, in transform_func_def
    func_ir, func_reg = gen_func_item(builder, fdef, fdef.name, sig)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/function.py", line 324, in gen_func_item
    builder.accept(fitem.body)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/builder.py", line 290, in accept
    node.accept(self.visitor)
  File "/home/stas/Documents/Work/mypy/mypy/nodes.py", line 1280, in accept
    return visitor.visit_block(self)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/visitor.py", line 190, in visit_block
    transform_block(self.builder, block)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/statement.py", line 130, in transform_block
    builder.accept(stmt)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/builder.py", line 290, in accept
    node.accept(self.visitor)
  File "/home/stas/Documents/Work/mypy/mypy/nodes.py", line 813, in accept
    return visitor.visit_func_def(self)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/visitor.py", line 181, in visit_func_def
    transform_func_def(self.builder, fdef)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/function.py", line 101, in transform_func_def
    func_ir, func_reg = gen_func_item(builder, fdef, fdef.name, sig)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/function.py", line 324, in gen_func_item
    builder.accept(fitem.body)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/builder.py", line 290, in accept
    node.accept(self.visitor)
  File "/home/stas/Documents/Work/mypy/mypy/nodes.py", line 1280, in accept
    return visitor.visit_block(self)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/visitor.py", line 190, in visit_block
    transform_block(self.builder, block)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/statement.py", line 130, in transform_block
    builder.accept(stmt)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/builder.py", line 290, in accept
    node.accept(self.visitor)
  File "/home/stas/Documents/Work/mypy/mypy/nodes.py", line 813, in accept
    return visitor.visit_func_def(self)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/visitor.py", line 181, in visit_func_def
    transform_func_def(self.builder, fdef)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/function.py", line 101, in transform_func_def
    func_ir, func_reg = gen_func_item(builder, fdef, fdef.name, sig)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/function.py", line 324, in gen_func_item
    builder.accept(fitem.body)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/builder.py", line 290, in accept
    node.accept(self.visitor)
  File "/home/stas/Documents/Work/mypy/mypy/nodes.py", line 1280, in accept
    return visitor.visit_block(self)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/visitor.py", line 190, in visit_block
    transform_block(self.builder, block)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/statement.py", line 130, in transform_block
    builder.accept(stmt)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/builder.py", line 290, in accept
    node.accept(self.visitor)
  File "/home/stas/Documents/Work/mypy/mypy/nodes.py", line 1367, in accept
    return visitor.visit_assignment_stmt(self)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/visitor.py", line 202, in visit_assignment_stmt
    transform_assignment_stmt(self.builder, stmt)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/statement.py", line 199, in transform_assignment_stmt
    rvalue_reg = builder.accept(stmt.rvalue)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/builder.py", line 276, in accept
    res = node.accept(self.visitor)
  File "/home/stas/Documents/Work/mypy/mypy/nodes.py", line 2470, in accept
    return visitor.visit_dictionary_comprehension(self)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/visitor.py", line 323, in visit_dictionary_comprehension
    return transform_dictionary_comprehension(self.builder, expr)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/expression.py", line 1037, in transform_dictionary_comprehension
    comprehension_helper(builder, loop_params, gen_inner_stmts, o.line)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/for_helpers.py", line 359, in comprehension_helper
    handle_loop(loop_params)
    ~~~~~~~~~~~^^^^^^^^^^^^^
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/for_helpers.py", line 319, in handle_loop
    for_loop_helper(
    ~~~~~~~~~~~~~~~^
        builder,
        ^^^^^^^^
    ...<5 lines>...
        line=line,
        ^^^^^^^^^^
    )
    ^
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/for_helpers.py", line 104, in for_loop_helper
    for_gen = make_for_loop_generator(
        builder, index, expr, body_block, normal_loop_exit, line, is_async=is_async
    )
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/for_helpers.py", line 496, in make_for_loop_generator
    target_type = builder.get_dict_item_type(expr.callee.expr)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/builder.py", line 995, in get_dict_item_type
    key_type = self.get_dict_key_type(expr)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/builder.py", line 979, in get_dict_key_type
    dict_base_types = self.get_dict_base_type(expr)
  File "/home/stas/Documents/Work/mypy/mypyc/irbuild/builder.py", line 973, in get_dict_base_type
    assert isinstance(t, Instance), t
           ~~~~~~~~~~^^^^^^^^^^^^^
a.py:12: AssertionError: PARAM.kwargs`-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash topic-mypyc mypyc bugs topic-paramspec PEP 612, ParamSpec, Concatenate
Projects
None yet
2 participants