python / python/mypy

Mypy daemon crash related to decorator

Open
#19,819 10 comments 0 reactions 1 assignee View on GitHub

@JukkaL is already working on this.

Since Sep 10, 2025.

crash topic-daemon
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

This mypy daemon test case triggers a crash:

[case testUndefinedDecoratorRefersToInit]
import m

[file m.py]
class C:
    def __init__(self, x: int) -> None: ...

[file m.py.2]
from typing_extensions import Self

class C:
    def __init__(self, x: int) -> None: ...

    @classmethod
    @copy_only_params_from_method(__init__)
    async def create(cls, *args, **kwargs) -> Self:
        res = cls(*args, **kwargs)
        await res.async_init()
        return res

    async def async_init(self) -> None: ...
[builtins fixtures/tuple.pyi]
[out]
<omitted>

I'm not yet sure what is going on, and it may be possible to simplify this further.

Traceback:

/Users/jukka/src/mypy/mypy/test/testfinegrained.py:116: in run_case
    output, triggered = self.perform_step(
/Users/jukka/src/mypy/mypy/test/testfinegrained.py:220: in perform_step
    new_messages = self.run_check(server, sources)
/Users/jukka/src/mypy/mypy/test/testfinegrained.py:170: in run_check
    response = server.check(sources, export_types=False, is_tty=False, terminal_width=-1)
/Users/jukka/src/mypy/mypy/dmypy_server.py:431: in check
    messages = self.fine_grained_increment(sources, explicit_export_types=export_types)
/Users/jukka/src/mypy/mypy/dmypy_server.py:589: in fine_grained_increment
    messages = self.fine_grained_manager.update(changed, removed)
/Users/jukka/src/mypy/mypy/server/update.py:265: in update
    result = self.update_one(
/Users/jukka/src/mypy/mypy/server/update.py:367: in update_one
    result = self.update_module(next_id, next_path, next_id in removed_set, followed)
/Users/jukka/src/mypy/mypy/server/update.py:432: in update_module
    result = update_module_isolated(
/Users/jukka/src/mypy/mypy/server/update.py:668: in update_module_isolated
    state.type_check_first_pass()
/Users/jukka/src/mypy/mypy/build.py:2344: in type_check_first_pass
    self.type_checker().check_first_pass()
/Users/jukka/src/mypy/mypy/checker.py:524: in check_first_pass
    self.accept(d)
/Users/jukka/src/mypy/mypy/checker.py:637: in accept
    report_internal_error(err, self.errors.file, stmt.line, self.errors, self.options)
/Users/jukka/src/mypy/mypy/errors.py:1331: in report_internal_error
    raise err
/Users/jukka/src/mypy/mypy/checker.py:635: in accept
    stmt.accept(self)
/Users/jukka/src/mypy/mypy/nodes.py:1445: in accept
    return visitor.visit_class_def(self)
/Users/jukka/src/mypy/mypy/checker.py:2665: in visit_class_def
    self.accept(defn.defs)
/Users/jukka/src/mypy/mypy/checker.py:637: in accept
    report_internal_error(err, self.errors.file, stmt.line, self.errors, self.options)
/Users/jukka/src/mypy/mypy/errors.py:1331: in report_internal_error
    raise err
/Users/jukka/src/mypy/mypy/checker.py:635: in accept
    stmt.accept(self)
/Users/jukka/src/mypy/mypy/nodes.py:1542: in accept
    return visitor.visit_block(self)
/Users/jukka/src/mypy/mypy/checker.py:3126: in visit_block
    self.accept(s)
/Users/jukka/src/mypy/mypy/checker.py:637: in accept
    report_internal_error(err, self.errors.file, stmt.line, self.errors, self.options)
/Users/jukka/src/mypy/mypy/errors.py:1331: in report_internal_error
    raise err
/Users/jukka/src/mypy/mypy/checker.py:635: in accept
    stmt.accept(self)
/Users/jukka/src/mypy/mypy/nodes.py:1127: in accept
    return visitor.visit_decorator(self)
/Users/jukka/src/mypy/mypy/checker.py:5412: in visit_decorator
    self.visit_decorator_inner(e)
/Users/jukka/src/mypy/mypy/checker.py:5419: in visit_decorator_inner
    self.check_func_item(e.func, name=e.func.name, allow_empty=allow_empty)
/Users/jukka/src/mypy/mypy/checker.py:1231: in check_func_item
    self.check_func_def(defn, typ, name, allow_empty)
/Users/jukka/src/mypy/mypy/checker.py:1504: in check_func_def
    self.accept(item.body)
/Users/jukka/src/mypy/mypy/checker.py:637: in accept
    report_internal_error(err, self.errors.file, stmt.line, self.errors, self.options)
/Users/jukka/src/mypy/mypy/errors.py:1331: in report_internal_error
    raise err
/Users/jukka/src/mypy/mypy/checker.py:635: in accept
    stmt.accept(self)
/Users/jukka/src/mypy/mypy/nodes.py:1542: in accept
    return visitor.visit_block(self)
/Users/jukka/src/mypy/mypy/checker.py:3126: in visit_block
    self.accept(s)
/Users/jukka/src/mypy/mypy/checker.py:637: in accept
    report_internal_error(err, self.errors.file, stmt.line, self.errors, self.options)
/Users/jukka/src/mypy/mypy/errors.py:1331: in report_internal_error
    raise err
/Users/jukka/src/mypy/mypy/checker.py:635: in accept
    stmt.accept(self)
/Users/jukka/src/mypy/mypy/nodes.py:1629: in accept
    return visitor.visit_assignment_stmt(self)
/Users/jukka/src/mypy/mypy/checker.py:3177: in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
/Users/jukka/src/mypy/mypy/checker.py:3389: in check_assignment
    rvalue_type = self.expr_checker.accept(rvalue, type_context=type_context)
/Users/jukka/src/mypy/mypy/checkexpr.py:6050: in accept
    report_internal_error(
/Users/jukka/src/mypy/mypy/errors.py:1331: in report_internal_error
    raise err
/Users/jukka/src/mypy/mypy/checkexpr.py:6046: in accept
    typ = self.accept_maybe_cache(node, type_context=type_context)
/Users/jukka/src/mypy/mypy/checkexpr.py:6081: in accept_maybe_cache
    typ = node.accept(self)
/Users/jukka/src/mypy/mypy/nodes.py:2253: in accept
    return visitor.visit_call_expr(self)
/Users/jukka/src/mypy/mypy/checkexpr.py:494: in visit_call_expr
    return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
/Users/jukka/src/mypy/mypy/checkexpr.py:631: in visit_call_expr_inner
    ret_type = self.check_call_expr_with_callee_type(
/Users/jukka/src/mypy/mypy/checkexpr.py:1481: in check_call_expr_with_callee_type
    ret_type, callee_type = self.check_call(
/Users/jukka/src/mypy/mypy/checkexpr.py:1629: in check_call
    item = self.analyze_type_type_callee(callee.item, context)
/Users/jukka/src/mypy/mypy/checkexpr.py:1885: in analyze_type_type_callee
    callee = self.analyze_type_type_callee(get_proper_type(item.upper_bound), context)
/Users/jukka/src/mypy/mypy/checkexpr.py:1863: in analyze_type_type_callee
    res = type_object_type(item.type, self.named_type)
/Users/jukka/src/mypy/mypy/typeops.py:177: in type_object_type
    init_index = info.mro.index(init_method.node.info)
E   ValueError: <TypeInfo m.C> is not in list
---------------------------------------------------- Captured stdout call ----------------------------------------------------
tmp/m.py:7: error: Name "copy_only_params_from_method" is not defined
---------------------------------------------------- Captured stderr call ----------------------------------------------------
tmp/m.py:9: 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.19.0+dev.fd0526545419028090f064ba4c1fa6e576ccdd6b.dirty
tmp/m.py:9: 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.19.0+dev.fd0526545419028090f064ba4c1fa6e576ccdd6b.dirty
tmp/m.py:9: 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.19.0+dev.fd0526545419028090f064ba4c1fa6e576ccdd6b.dirty
tmp/m.py:6: 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.19.0+dev.fd0526545419028090f064ba4c1fa6e576ccdd6b.dirty
tmp/m.py:4: 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.19.0+dev.fd0526545419028090f064ba4c1fa6e576ccdd6b.dirty
tmp/m.py:3: 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.19.0+dev.fd0526545419028090f064ba4c1fa6e576ccdd6b.dirty
tmp/m.py: 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.19.0+dev.fd0526545419028090f064ba4c1fa6e576ccdd6b.dirty

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.