Skip to content

crash for a very specific invocation of mypy: assert isinstance(visitor, SyntheticTypeVisitor) #19286

Open
@asottile-sentry

Description

@asottile-sentry

Crash Report

unfortunately I have not been able to narrow this down further -- but will include a full reproduction

rm -rf sentry
git init -q sentry
cd sentry
git remote add origin https://github.com/getsentry/sentry
git fetch --depth=1 origin 9f17c976f666881dea7f0c777adaff01b13b6675
git checkout -q FETCH_HEAD

python3.13 -m venv .venv
.venv/bin/python -m tools.fast_editable --path .
.venv/bin/pip install -qq -r requirements-dev-frozen.txt
.venv/bin/pip uninstall mypy -yqq
.venv/bin/pip install git+https://github.com/python/mypy

.venv/bin/mypy src/sentry/net/socket.py --show-traceback

for some reason it seems to be ok (not crash at least!) if I run mypy on different files in the source tree such as mypy src/sentry

Traceback

/private/tmp/sentry/src/sentry/identity/bitbucket/provider.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.17.0+dev.8241059c14f99ad750ae3ac0de6a4795bf990f61
Traceback (most recent call last):
  File "/private/tmp/sentry/./.venv/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/main.py", line 127, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/main.py", line 211, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/build.py", line 191, in build
    result = _build(
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/build.py", line 267, in _build
    graph = dispatch(sources, manager, stdout)
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/build.py", line 2939, in dispatch
    process_graph(graph, manager)
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/build.py", line 3337, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/build.py", line 3432, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/semanal_main.py", line 103, in semantic_analysis_for_scc
    check_type_arguments(graph, scc, errors)
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/semanal_main.py", line 436, in check_type_arguments
    with state.wrap_context():
  File "/opt/homebrew/Cellar/[email protected]/3.13.4/Frameworks/Python.framework/Versions/3.13/lib/python3.13/contextlib.py", line 162, in __exit__
    self.gen.throw(value)
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/build.py", line 2062, in wrap_context
    yield
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/semanal_main.py", line 438, in check_type_arguments
    state.tree.accept(analyzer)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/nodes.py", line 349, in accept
    return visitor.visit_mypy_file(self)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/semanal_typeargs.py", line 68, in visit_mypy_file
    super().visit_mypy_file(o)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/traverser.py", line 119, in visit_mypy_file
    d.accept(self)
    ~~~~~~~~^^^^^^
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/nodes.py", line 1238, in accept
    return visitor.visit_class_def(self)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/semanal_typeargs.py", line 78, in visit_class_def
    super().visit_class_def(defn)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/mixedtraverser.py", line 49, in visit_class_def
    base.accept(self)
    ~~~~~~~~~~~^^^^^^
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/types.py", line 1488, in accept
    return visitor.visit_instance(self)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/semanal_typeargs.py", line 124, in visit_instance
    _, is_invalid = self.validate_args(info.name, t.args, info.defn.type_vars, t)
                    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/semanal_typeargs.py", line 203, in validate_args
    if not object_upper_bound and not is_subtype(arg, upper_bound):
                                      ~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/subtypes.py", line 190, in is_subtype
    return _is_subtype(left, right, subtype_context, proper_subtype=False)
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/subtypes.py", line 357, in _is_subtype
    return left.accept(SubtypeVisitor(orig_right, subtype_context, proper_subtype))
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/sentry/.venv/lib/python3.13/site-packages/mypy/types.py", line 3176, in accept
    assert isinstance(visitor, SyntheticTypeVisitor)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 
/private/tmp/sentry/src/sentry/identity/bitbucket/provider.py: : note: use --pdb to drop into pdb

To Reproduce

see above -- reproduction unfortunately uses https://github.com/getsentry/sentry which is a fairly large codebase, lots of dependencies, a quite complicated mypy config, and several mypy plugins.

Your Environment

  • Mypy version used: current HEAD
  • Mypy command-line flags: (see above)
  • Mypy configuration options from mypy.ini (and other config files): (see above)
  • Python version used: 3.13.1
  • Operating system and version: arm64 macos x though I'm not sure it matters

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions