Skip to content

Typecheck crashes with mypy.types.TypeVarId object expected; got int #19857

Closed as duplicate

Description

@fjarri

I am still working on an MRE, the problem is kind of hard to isolate, but perhaps it's already a known issue.

The failure can be seen in this CI run: https://github.com/fjarri-eth/pons/actions/runs/17743317902/job/50422375174?pr=82

Locally, with traceback enabled (Python 3.10.10, mypy 1.18.1, trio 0.31.0, trio-typing 0.10.0):

> mypy pons --show-traceback
/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/trio-stubs/__init__.pyi:135: 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.18.1
Traceback (most recent call last):
  File "mypy/checker.py", line 641, in accept
  File "mypy/nodes.py", line 1122, in accept
  File "mypy/checker.py", line 5414, in visit_decorator
  File "mypy/checker.py", line 5450, in visit_decorator_inner
  File "mypy/checkexpr.py", line 1605, in check_call
  File "mypy/checkexpr.py", line 1848, in check_callable_call
  File "mypy/checkexpr.py", line 1286, in apply_function_plugin
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/trio_typing/plugin.py", line 464, in takes_callable_and_args_callback
    TypeVarType(
  File "mypy/types.py", line 658, in __init__
TypeError: mypy.types.TypeVarId object expected; got int
/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/trio-stubs/__init__.pyi:135: : note: use --pdb to drop into pdb

(pons library doesn't even use trio, only the tests do, so I'm still figuring out how to isolate this)

With mypy trunk (mypy-1.19.0+dev.73affc0c60aa8d9a7fdc43c8d57fd65c9ea870f1) the traceback is longer, but the issue seems to be the same:

Traceback (most recent call last):
  File "/Users/bogdan/.pyenv/versions/pons/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/main.py", line 127, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/main.py", line 211, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/build.py", line 196, in build
    result = _build(
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/build.py", line 272, in _build
    graph = dispatch(sources, manager, stdout)
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/build.py", line 2946, in dispatch
    process_graph(graph, manager)
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/build.py", line 3346, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/build.py", line 3475, in process_stale_scc
    meta_tuples[id] = graph[id].write_cache()
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/build.py", line 2507, in write_cache
    new_interface_hash, meta_tuple = write_cache(
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/build.py", line 1595, in write_cache
    data = tree.serialize()
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/nodes.py", line 407, in serialize
    "names": self.names.serialize(self._fullname),
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/nodes.py", line 4652, in serialize
    data[key] = value.serialize(fullname, key)
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/nodes.py", line 4545, in serialize
    data["node"] = self.node.serialize()
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/nodes.py", line 3819, in serialize
    "names": self.names.serialize(self.fullname),
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/nodes.py", line 4652, in serialize
    data[key] = value.serialize(fullname, key)
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/nodes.py", line 4545, in serialize
    data["node"] = self.node.serialize()
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/nodes.py", line 1133, in serialize
    "var": self.var.serialize(),
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/nodes.py", line 1305, in serialize
    "type": None if self.type is None else self.type.serialize(),
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/types.py", line 2685, in serialize
    return {".class": "Overloaded", "items": [t.serialize() for t in self.items]}
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/types.py", line 2685, in <listcomp>
    return {".class": "Overloaded", "items": [t.serialize() for t in self.items]}
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/types.py", line 2535, in serialize
    "arg_types": [t.serialize() for t in self.arg_types],
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/types.py", line 2535, in <listcomp>
    "arg_types": [t.serialize() for t in self.arg_types],
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/types.py", line 2535, in serialize
    "arg_types": [t.serialize() for t in self.arg_types],
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/types.py", line 2535, in <listcomp>
    "arg_types": [t.serialize() for t in self.arg_types],
  File "/Users/bogdan/.pyenv/versions/3.10.10/envs/pons/lib/python3.10/site-packages/mypy/types.py", line 691, in serialize
    assert not self.id.is_meta_var()
AttributeError: 'int' object has no attribute 'is_meta_var'

mypy settings in the project file:

[tool.mypy]
plugins = "trio_typing.plugin"
strict = true
warn_unreachable = true
implicit_reexport = true

Activity

  1. fjarri commented on Sep 15, 2025

    @fjarri
    Author

    Ah, actually the MRE turned out to be simple.

    pyproject.toml:

    [project]
    name = "mypy-test"
    version = "0.0.0"
    requires-python = ">=3.10"
    
    [tool.mypy]
    plugins = "trio_typing.plugin"
    strict = true
    warn_unreachable = true
    implicit_reexport = true

    t.py:

    import trio

    mypy t.py:

    /Users/bogdan/.pyenv/versions/3.10.10/envs/mypy-test/lib/python3.10/site-packages/trio-stubs/__init__.pyi:135: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
    https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
    If this issue continues with mypy master, please report a bug at https://github.com/python/mypy/issues
    version: 1.18.1
    /Users/bogdan/.pyenv/versions/3.10.10/envs/mypy-test/lib/python3.10/site-packages/trio-stubs/__init__.pyi:135: : note: please use --show-traceback to print a traceback when reporting a bug
    

    pip list:

    Package            Version
    ------------------ -----------
    async-generator    1.10
    attrs              25.3.0
    exceptiongroup     1.3.0
    idna               3.10
    importlib_metadata 8.7.0
    mypy               1.18.1
    mypy_extensions    1.1.0
    outcome            1.3.0.post0
    packaging          25.0
    pathspec           0.12.1
    pip                22.3.1
    setuptools         65.5.0
    sniffio            1.3.1
    sortedcontainers   2.4.0
    tomli              2.2.1
    trio               0.31.0
    trio-typing        0.10.0
    typing_extensions  4.15.0
    zipp               3.23.0
    
  2. brianschubert commented on Sep 15, 2025

    @brianschubert
    Collaborator

    Thanks for the report. Note that the exception is coming from inside the trio_typing plugin. You'll need to report this to trio-typing. You can point them to the discussion in #17671. I'm afraid there isn't anything for us to do on the mypy side.

    Closing as duplicate of #17671 (different plugin, but same issue)

  3. added and removed
    bugmypy got something wrong
    on Sep 15, 2025
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions