Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[2.0 regression] INTERNAL ERROR: AssertionError in visit_decorator_inner on @types.coroutine generator function #21426

Description

@agners

Bug Report

mypy 2.0.0 crashes with an AssertionError (assert isinstance(defn.type, CallableType)) when checking a generator function decorated with @types.coroutine. This is a regression: mypy 1.20.2 accepts the same code without issue. The bug also reproduces on master as of commit 11f945b.

Originally encountered while running mypy --ignore-missing-imports supervisor on the Home Assistant Supervisor project; the crash occurs inside the aiodocker dependency at aiodocker/jsonstream.py:21.

To Reproduce

import types

@types.coroutine
def f():
    yield
    return 1

Run: mypy tiny.py

Expected Behavior

No errors. @types.coroutine is a stdlib decorator that turns a generator function into a coroutine; the same file checks cleanly with mypy 1.x.

Actual Behavior

tiny.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: 2.0.0
tiny.py:3: note: use --pdb to drop into pdb
Traceback (most recent call last):
  File "mypy/checker.py", line 765, in accept
  File "mypy/nodes.py", line 1352, in accept
  File "mypy/checker.py", line 5716, in visit_decorator
    self.visit_decorator_inner(e)
  File "mypy/checker.py", line 5724, in visit_decorator_inner
    assert isinstance(defn.type, CallableType)
AssertionError

Your Environment

  • Mypy version used: 2.0.0 (compiled: yes); confirmed working on 1.20.2
  • Mypy command-line flags: none (also reproduces with --ignore-missing-imports and --show-traceback)
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.14.4

Activity

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