python / python/mypy

stubgen misses generated modules

Open
#13,904 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-stubgen
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with stubgen -p cv2 and compare the generated stubs with the listed dynamically generated modules. Then trace stubgen's recursive package discovery from that command entry point; done means stubs are generated for the named modules, including cv2.Error, cv2.cuda, and cv2.videoio_registry.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.