Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def __init__(
quiet: bool,
export_less: bool,
include_docstrings: bool,
include_vendored: bool,
) -> None:
# See parse_options for descriptions of the flags.
self.pyversion = pyversion
Expand All @@ -234,6 +235,7 @@ def __init__(
self.quiet = quiet
self.export_less = export_less
self.include_docstrings = include_docstrings
self.include_vendored = include_vendored


class StubSource:
Expand Down Expand Up @@ -1543,10 +1545,15 @@ def get_qualified_name(o: Expression) -> str:
return ERROR_MARKER


def remove_blacklisted_modules(modules: list[StubSource]) -> list[StubSource]:
return [
module for module in modules if module.path is None or not is_blacklisted_path(module.path)
]
def remove_blacklisted_modules(modules: list[StubSource], quiet: bool = False) -> list[StubSource]:
"""Remove blacklisted modules and optionally warn about them."""
result = []
for module in modules:
if module.path is None or not is_blacklisted_path(module.path):
result.append(module)
elif not quiet:
print(f"Skipping vendored module: {module.module}")
return result


def split_pyc_from_py(modules: list[StubSource]) -> tuple[list[StubSource], list[StubSource]]:
Expand Down Expand Up @@ -1595,7 +1602,8 @@ def collect_build_targets(
py_modules = [StubSource(m.module, m.path) for m in source_list]
c_modules = []

py_modules = remove_blacklisted_modules(py_modules)
if not options.include_vendored:
py_modules = remove_blacklisted_modules(py_modules, options.quiet)
pyc_mod, py_mod = split_pyc_from_py(py_modules)
return py_mod, pyc_mod, c_modules

Expand Down Expand Up @@ -1947,6 +1955,11 @@ def parse_options(args: list[str]) -> Options:
action="store_true",
help="include existing docstrings with the stubs",
)
parser.add_argument(
"--include-vendored",
action="store_true",
help="generate stubs for vendored packages (e.g., packages in 'vendor', '_vendor', etc.)",
)
parser.add_argument("-v", "--verbose", action="store_true", help="show more verbose messages")
parser.add_argument("-q", "--quiet", action="store_true", help="show fewer messages")
parser.add_argument(
Expand Down Expand Up @@ -2033,6 +2046,7 @@ def parse_options(args: list[str]) -> Options:
quiet=ns.quiet,
export_less=ns.export_less,
include_docstrings=ns.include_docstrings,
include_vendored=ns.include_vendored,
)


Expand Down