Skip to content

stubgen misses generated modules #13904

Open
@Avasam

Description

@Avasam

Bug Report

When using stubgen to recursively generate stubs for a package, it misses dynamically generated modules.

To Reproduce
Example using cv2. Every module that doesn't come from a file is not picked-up:

import cv2
import inspect
[print(x) for x in inspect.getmembers(cv2, inspect.ismodule)] 
('', <module 'cv2' from 'C:\\Users\\Avasam\\Documents\\Git\\typeshed\\.venv\\lib\\site-packages\\cv2\\__init__.py'>)
('Error', <module 'cv2.Error'>)
('_native', <module 'cv2.cv2' from 'C:\\Users\\Avasam\\Documents\\Git\\typeshed\\.venv\\lib\\site-packages\\cv2\\cv2.pyd'>)
('cuda', <module 'cv2.cuda'>)
('cv2', <module 'cv2.cv2' from 'C:\\Users\\Avasam\\Documents\\Git\\typeshed\\.venv\\lib\\site-packages\\cv2\\cv2.pyd'>)
('data', <module 'cv2.data' from 'C:\\Users\\Avasam\\Documents\\Git\\typeshed\\.venv\\lib\\site-packages\\cv2\\data\\__init__.py'>)
('detail', <module 'cv2.detail'>)
('dnn', <module 'cv2.dnn'>)
('fisheye', <module 'cv2.fisheye'>)
('flann', <module 'cv2.flann'>)
('gapi', <module 'cv2.gapi' from 'C:\\Users\\Avasam\\Documents\\Git\\typeshed\\.venv\\lib\\site-packages\\cv2\\gapi\\__init__.py'>)
('importlib', <module 'importlib' from 'C:\\Program Files\\Python39\\lib\\importlib\\__init__.py'>)
('ipp', <module 'cv2.ipp'>)
('load_config_py3', <module 'cv2.load_config_py3' from 'C:\\Users\\Avasam\\Documents\\Git\\typeshed\\.venv\\lib\\site-packages\\cv2\\load_config_py3.py'>)
('mat_wrapper', <module 'cv2.mat_wrapper' from 'C:\\Users\\Avasam\\Documents\\Git\\typeshed\\.venv\\lib\\site-packages\\cv2\\mat_wrapper\\__init__.py'>)
('misc', <module 'cv2.misc' from 'C:\\Users\\Avasam\\Documents\\Git\\typeshed\\.venv\\lib\\site-packages\\cv2\\misc\\__init__.py'>)
('ml', <module 'cv2.ml'>)
('numpy', <module 'numpy' from 'C:\\Users\\Avasam\\Documents\\Git\\typeshed\\.venv\\lib\\site-packages\\numpy\\__init__.py'>)
('ocl', <module 'cv2.ocl'>)
('ogl', <module 'cv2.ogl'>)
('os', <module 'os' from 'C:\\Program Files\\Python39\\lib\\os.py'>)
('parallel', <module 'cv2.parallel'>)
('samples', <module 'cv2.samples'>)
('segmentation', <module 'cv2.segmentation'>)
('sys', <module 'sys' (built-in)>)
('utils', <module 'cv2.utils' from 'C:\\Users\\Avasam\\Documents\\Git\\typeshed\\.venv\\lib\\site-packages\\cv2\\utils\\__init__.py'>)
('version', <module 'cv2.version' from 'C:\\Users\\Avasam\\Documents\\Git\\typeshed\\.venv\\lib\\site-packages\\cv2\\version.py'>)
('videoio_registry', <module 'cv2.videoio_registry'>)

Expected Behavior

When running stubgen -p cv2, stubs should be generated for cv2.Error, cv2.cuda, cv2.detail, cv2.dnn, cv2.fisheye, cv2.flann, cv2.ipp, cv2.ml, cv2.ocl, cv2.ogl, cv2.parallel, cv2.samples, cv2.segmentation, and cv2.videoio_registry

Actual Behavior

They're not. The results seem to be what we get from import cv2; iport pkgutil; pkgutil.iter_modules(cv2.__path__)]

Your Environment

  • Mypy version used: 0.982 (compiled: yes)
  • Mypy command-line flags: stubgen -p cv2
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.9.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions