diff --git a/pybind11_stubgen/__init__.py b/pybind11_stubgen/__init__.py index f3a9215..a24f692 100644 --- a/pybind11_stubgen/__init__.py +++ b/pybind11_stubgen/__init__.py @@ -73,6 +73,7 @@ class CLIArgs(Namespace): numpy_array_remove_parameters: bool print_invalid_expressions_as_is: bool print_safe_value_reprs: re.Pattern | None + print_disable_value_comments: bool exit_code: bool dry_run: bool stub_extension: str @@ -190,6 +191,12 @@ def regex_colon_path(regex_path: str) -> tuple[re.Pattern, str]: type=regex, help="Override the print-safe check for values matching REGEX", ) + parser.add_argument( + "--print-disable-value-comments", + default=False, + action="store_true", + help="Disable printing attribute value comments, i.e., '# value = '", + ) parser.add_argument( "--exit-code", @@ -308,7 +315,10 @@ def main(): args = arg_parser().parse_args(namespace=CLIArgs()) parser = stub_parser_from_args(args) - printer = Printer(invalid_expr_as_ellipses=not args.print_invalid_expressions_as_is) + printer = Printer( + invalid_expr_as_ellipses=not args.print_invalid_expressions_as_is, + print_disable_value_comments=args.print_disable_value_comments, + ) out_dir, sub_dir = to_output_and_subdir( output_dir=args.output_dir, diff --git a/pybind11_stubgen/printer.py b/pybind11_stubgen/printer.py index 8ef4af2..bfffd4e 100644 --- a/pybind11_stubgen/printer.py +++ b/pybind11_stubgen/printer.py @@ -30,8 +30,11 @@ def indent_lines(lines: list[str], by=4) -> list[str]: class Printer: - def __init__(self, invalid_expr_as_ellipses: bool): + def __init__( + self, invalid_expr_as_ellipses: bool, print_disable_value_comments: bool + ): self.invalid_expr_as_ellipses = invalid_expr_as_ellipses + self.print_disable_value_comments = print_disable_value_comments def print_alias(self, alias: Alias) -> list[str]: return [f"{alias.name} = {alias.origin}"] @@ -48,7 +51,7 @@ def print_attribute(self, attr: Attribute) -> list[str]: else: if attr.annotation is None: parts.append(" = ...") - if attr.value is not None: + if attr.value is not None and not self.print_disable_value_comments: parts.append(f" # value = {self.print_value(attr.value)}") return ["".join(parts)]