Skip to content

__init_subclass__ with classmethod raises IndexError in stubtest #15397

Closed

Description

@rayzchen

Bug Report

Stubtest raises IndexError: list index out of range when a __init_subclass__ method with the classmethod decorator is used.

To Reproduce

https://github.com/rayzchen/stubtest-bug

Run python -m mypy.stubtest mod

Actual Behavior

init subclass
Traceback (most recent call last):
  File "D:\RayChen\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\RayChen\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "D:\RayChen\Programs\Python\Python310\lib\site-packages\mypy\stubtest.py", line 1879, in <module>
    sys.exit(main())
  File "D:\RayChen\Programs\Python\Python310\lib\site-packages\mypy\stubtest.py", line 1875, in main
    return test_stubs(parse_options(sys.argv[1:]))
  File "D:\RayChen\Programs\Python\Python310\lib\site-packages\mypy\stubtest.py", line 1748, in test_stubs
    for error in test_module(module):
  File "D:\RayChen\Programs\Python\Python310\lib\site-packages\mypy\stubtest.py", line 218, in test_module
    yield from verify(stub, runtime, [module_name])
  File "D:\RayChen\Programs\Python\Python310\lib\site-packages\mypy\stubtest.py", line 396, in verify_mypyfile
    yield from verify(stub_entry, runtime_entry, object_path + [entry])
  File "D:\RayChen\Programs\Python\Python310\lib\site-packages\mypy\stubtest.py", line 534, in verify_typeinfo
    yield from verify(stub_to_verify, runtime_attr, object_path + [entry])
  File "D:\RayChen\Programs\Python\Python310\lib\site-packages\mypy\stubtest.py", line 1254, in verify_decorator
    yield from verify(func, runtime, object_path)
  File "D:\RayChen\Programs\Python\Python310\lib\site-packages\mypy\stubtest.py", line 974, in verify_funcitem
    stub_sig = Signature.from_funcitem(stub)
  File "D:\RayChen\Programs\Python\Python310\lib\site-packages\mypy\stubtest.py", line 730, in from_funcitem
    stub_args = maybe_strip_cls(stub.name, stub.arguments)
  File "D:\RayChen\Programs\Python\Python310\lib\site-packages\mypy\stubtest.py", line 674, in maybe_strip_cls
    if args[0].variable.name == "cls":
IndexError: list index out of range

Your Environment

  • Mypy version used: 1.3.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10.6

Activity

  1. hauntsaninja commented on Jun 8, 2023

    @hauntsaninja
    Collaborator

    Thanks for the report!

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