Skip to content

stubgenc.py throw TypeError: unbound method type.mro() needs an argument #10137

@gen-xu

Description

@gen-xu

Bug Report

When I was trying to use stubgen to generate pyi for the PyAV package, an error is being thrown.

  File "mypy\stubgenc.py", line 315, in generate_c_type_stub
TypeError: unbound method type.mro() needs an argument

After a bit investigation in stubgenc.py and PyAV. I found the issue is caused by these
https://github.com/python/mypy/blob/master/mypy/stubgenc.py#L299
https://github.com/python/mypy/blob/master/mypy/stubgenc.py#L355
Basically, when invoking obj.mro() with EnumType defined in https://github.com/PyAV-Org/PyAV/blob/main/av/enum.pyx#L25, it resolves into <type>.mro() and complains missing argument, because EnumType inherits type.
The minimum case of this would just be python -c 'type.mro()'

To Reproduce

  1. Install PyAV with pip install av I am using 8.0.3 but most versions should work though
  2. Install mypy with pip install mypy I am using 0.812 but most versions with stubgen should behave similar
  3. Run command stubgen -p av or more specifically stubgen -m av.enum

Expected Behavior

It supposed to generate pyi file without throwing errors

Actual Behavior

PS C:\Users\Gen\Repos> stubgen -m av.enum
Traceback (most recent call last):
  File "c:\users\gen\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\gen\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\Gen\AppData\Local\Programs\Python\Python39\Scripts\stubgen.exe\__main__.py", line 7, in <module>
  File "mypy\stubgen.py", line 1582, in main
  File "mypy\stubgen.py", line 1475, in generate_stubs
  File "mypy\stubgenc.py", line 64, in generate_stub_for_c_module
  File "mypy\stubgenc.py", line 315, in generate_c_type_stub
TypeError: unbound method type.mro() needs an argument

Your Environment

  • Mypy version used: 0.812
  • Mypy command-line flags: stubgen -m av.enum
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.9.1
  • Operating system and version: Windows 10 Pro 19042.804

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions