Skip to content

NotImplementedError: Cannot serialize TypeGuardedType instance #20015

@skywall

Description

@skywall

Crash Report

When I include aditional dependency onnx-ir==0.1.10 into my pyproject.toml I start to receive error NotImplementedError: Cannot serialize TypeGuardedType instance.

Traceback

(mypy-bug-proj) skywall@me:~/lProjects/mypy-bug-minimal$ mypy . --show-traceback
Traceback (most recent call last):
  File "/home/skywall/lProjects/mypy-bug-minimal/.venv/bin/mypy", line 10, in <module>
    sys.exit(console_entry())
             ^^^^^^^^^^^^^^^
  File "/home/skywall/lProjects/mypy-bug-minimal/.venv/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/main.py", line 127, in main
  File "mypy/main.py", line 211, in run_build
  File "mypy/build.py", line 194, in build
  File "mypy/build.py", line 270, in _build
  File "mypy/build.py", line 2976, in dispatch
  File "mypy/build.py", line 3397, in process_graph
  File "mypy/build.py", line 3524, in process_stale_scc
  File "mypy/build.py", line 2538, in write_cache
  File "mypy/build.py", line 1587, in write_cache
  File "mypy/nodes.py", line 402, in serialize
  File "mypy/nodes.py", line 4641, in serialize
  File "mypy/nodes.py", line 4534, in serialize
  File "mypy/nodes.py", line 3814, in serialize
  File "mypy/nodes.py", line 4641, in serialize
  File "mypy/nodes.py", line 4534, in serialize
  File "mypy/nodes.py", line 1300, in serialize
  File "mypy/types.py", line 722, in serialize
  File "mypy/types.py", line 3300, in serialize
  File "mypy/types.py", line 295, in serialize

NotImplementedError: Cannot serialize TypeGuardedType instance

To Reproduce

This is minimal reproducible project I was able to create:

main.py:

import torch  # yes, only import

pyproject.toml:

[project]
name = "mypy-bug-proj"
version = "1.0.0"
description = "mypy-bug-project"
license-files = ["LICEN[CS]E*"]
keywords = []
requires-python = ">=3.11"
classifiers = [
    "Programming Language :: Python",
    "Intended Audience :: Developers",
]
dependencies = [
    "mypy",
    "torch",
    "onnx==1.17.0",
    "ml-dtypes==0.5.3",
    "onnx-ir==0.1.10",  # <- this is problematic dependency. If it's excluded mypy works fine
]

Your Environment

.python-version:

3.11

uv.lock: uv.lock.txt

  • Mypy version used: 1.18.2
  • Mypy command-line flags: -
  • Mypy configuration options from mypy.ini (and other config files): -
  • Python version used: 3.11.5
  • Operating system and version: Ubuntu 22.04 WSL

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions